问题
Suppose I have a python interpreter with many modules installed on my local system, and it has been tuned to just work.
Now I want to create a virtualenv to freeze these, so that they won't be broke by upgrading in the future.
How can I make it? Thanks.
I can't use pip freeze, because that's a cluster on which there's no pip and I don't have the privileges to install it. And I don't want the reinstall the modules either, I'm looking for that whether there's a cloning way.
回答1:
Run pip freeze to create a list of all modules currently installed on the system. Then make a virtualenv and install these modules.
pip freeze > env_modules.txt
virtualenv my_env && cd my_env && source bin/activate
pip install -r ../env_modules.txt
回答2:
Virtualenv does not work because it uses local python interpreter.
My solution is to use conda (anoconda or miniconda) to build the environment, so if you need some packages, you can just conda install them. Then copy it to the remote machine and run.
回答3:
I think better to recursively copy your virtualenv dir:
cp <old_env> <new_env> -R
I can't write full answer because I don't know do you use virtualwrapper or something else.
回答4:
I think the best is to use cpvirtualenv like this:
cpvirtualenv <name_of_virtualenv_to_be_copied> <name_of_new_virtualenv>
来源:https://stackoverflow.com/questions/14185288/how-to-create-a-virtualenv-by-cloning-the-current-local-environment