问题
By error, I forgot to specify the WORKON_HOME
variable before creating my virtual environments, and they were created in /root/.virtualenvs
directory. They worked fine, and I did some testing by activating certain environment and then doing (env)$ pip freeze
to see what specific modules are installed there.
So, whe I discovered the workon home path error, I needed to change the host directory to /usr/local/pythonenv
. I created it and moved all the contents of /root/.virtualenvs
directory to /usr/local/pythonenv
, and changed the value of WORKON_HOME
variable. Now, activating an environment using workon command seems to work fine (ie, the promt changes to (env)$
), however if I do (env)$ pip freeze
, I get way longer list of modules than before and those do not include the ones installed in that particular env before the move.
I guess that just moving the files and specifying another dir for WORKON_HOME
variable was not enough. Is there some config where I should specify the new location of the host directory, or some config files for the particular environment?
回答1:
Virtualenvs are not by default relocatable. You can use virtualenv --relocatable <virtualenv>
to turn an existing virtualenv into a relocatable one, and see if that works. But that option is experimental and not really recommended for use.
The most reliable way is to create new virtualenvs. Use pip freeze -l > requirements.txt
in the old ones to get a list of installed packages, create the new virtualenv, and use pip install -r requirements.txt
to install the packages in the new one.
回答2:
I used the virtualenv --relocatable
feature. It seemed to work but then I found a different python version installed:
$ . VirtualEnvs/moslog/bin/activate
(moslog)$ ~/VirtualEnvs/moslog/bin/mosloganalisys.py
python: error while loading shared libraries: libpython2.7.so.1.0: cannot open shared object file: No such file or directory
Remember to recreate the same virtualenv tree on the destination host.
来源:https://stackoverflow.com/questions/25364207/move-the-virtualenvs-to-another-host-folder