How to recreate a virtual env in python

前端 未结 2 1832
我在风中等你
我在风中等你 2020-12-19 23:42

I have installed virtualenv and virtualenvwrapper on Ubuntu 16.04 I have created one enviroment named env1

$ sudo apt-get install python-pip
$ pip install vi         


        
相关标签:
2条回答
  • 2020-12-20 00:22

    Your best option is to do this:

    virtualenv-1:

    pip freeze > requirements.txt 
    

    virtualenv-2:

    pip install -r requirements.txt
    

    Assuming they are both the on the same system and use the same Python, it is somewhat possible to just copy the site-packages:

    cp -Rp /environments/virtualenv-1/lib/python2.7/site-packages \
           /environments/virtualenv-2/lib/python2.7/site-packages
    

    This won't necessarily work though:

    • some packages will install dependencies and other things into /bin/ or elsewhere. most don't, but many do.
    • if the python versions for the virtualenvs differ -- even on a minor version -- that can break libraries that use c extensions.

    So your best bet is to pip freeze and reinstall from that file.

    0 讨论(0)
  • 2020-12-20 00:31

    pip install virtualenvwrapper and use the cpvirtualenv command

    cpvirtualenv ENVNAME [TARGETENVNAME]
    

    http://virtualenvwrapper.readthedocs.io/en/latest/command_ref.html#cpvirtualenv

    Remember to heed the warning

    Copying virtual environments is not well supported. Each virtualenv has 
    path information hard-coded into it, and there may be cases where the copy 
    code does not know to update a particular file. Use with caution.
    
    0 讨论(0)
提交回复
热议问题