pythonpython-3.xvirtualenvvirtualenv-commands

Can I move a virtualenv?


If I create a virtualenv, and I move it to a different folder, will it still work?

$ virtualenv -p /usr/bin/python3 /home/me/Env/my-python-venv
$ source Env/my-python-venv/bin/activate
(my-python-venv) $ 

...later that day, the virtual environment MOVED...

(my-python-venv) $ deactivate
$ mkdir -p /home/me/PeskyPartyPEnvs
$ mv /home/me/Env/my-python-venv /home/me/PeskyPartyPEnvs/

Will this work?

$ source /home/me/PeskyPartyPEnvs/my-python-venv/bin/activate
(my-python-venv) $ /home/me/PeskyPartyPEnvs/my-python-venv/bin/pip3 install foaas

I mean this as less of a question about the wisdom of trying this (unless that wisdom is humorous, of course), and more about whether it's possible. I really want to know whether it's possible to do in Python 3, or whether I just have to suck it up and clone it.

Can I just mv a virtualenv like that without sadness? I do want to avoid sadness.


I looked at Renaming a virtualenv folder without breaking it, but this question pertains not just to renaming a virtual environment, but to actually moving it to a different directory, including, potentially, a different user's directory. This is not the same as merely renaming a virtual environment, especially to people unfamiliar with virtualenvs.


Solution

  • BUT ALAS:

    No, you can't simply mv. There are workarounds, but it might be easier to reinstall.

    (my-python-venv)$ /home/me/PeskyPartyPEnvs/pip3 install foaas
    zsh: /home/me/PeskyPartyPEnvs/pip3: bad interpreter: /home/me/Env/my-python-venv/bin/python3: no such file or directory
    (my-python-venv)$ deactivate
    $ 
    

    ... presses enter a lot in frustration, and the following works

    $
    $
    $ pip3 search foaas
    

    Except it is not from my-python-venv, ergo sadness.

    Want to mv your virtualenv and use it, otherwise unmodified?

    Short Answer:

    I'll let Boromir say it, so he can make it clear:

    Well, ya can't.