How to duplicate virtualenv

前端 未结 6 1268
慢半拍i
慢半拍i 2020-12-07 07:45

I have an existing virtualenv with a lot of packages but an old version of Django.

What I want to do is duplicate this environment so I have another

相关标签:
6条回答
  • 2020-12-07 08:20

    virtualenvwrapper provides a command to duplicate virtualenv

    cpvirtualenv ENVNAME [TARGETENVNAME]
    
    0 讨论(0)
  • 2020-12-07 08:24

    If you are using Anaconda you can just run:

    conda create --name myclone --clone myenv
    

    This will copy myenv to the newly created environment called myclone.

    0 讨论(0)
  • 2020-12-07 08:26

    The easiest way is to use pip to generate a requirements file. A requirements file is basically a file that contains a list of all the python packages you want to install (or have already installed in case of file generated by pip), and what versions they're at.

    To generate a requirements file, go into your original virtualenv, and run:

    pip freeze > requirements.txt
    

    This will generate the requirements.txt file for you. If you open that file up in your favorite text editor, you'll see something like:

    Django==1.3
    Fabric==1.0.1
    etc...
    

    Now, edit the line that says Django==x.x to say Django==1.3 (or whatever version you want to install in your new virtualenv).

    Lastly, activate your new virtualenv, and run:

    pip install -r requirements.txt
    

    And pip will automatically download and install all the python modules listed in your requirements.txt file, at whatever versions you specified!

    0 讨论(0)
  • 2020-12-07 08:26

    Can you not simply:

    • Copy the existing virtual env directory to a new one
    • Update to the new Django?
    0 讨论(0)
  • 2020-12-07 08:35

    Easiest option is using virtualenv-clone package.

    To duplicate venv1 to venv2, follow these steps:

    1. Install virtualenv-clone in either venv1 or a dummy virtual environment venv_dummy. To create venv_dummy:

      python -m virtualenv venv_dummy
      source venv_dummy/bin/activate
      
    2. To install virtualenv-clone:

      (venv_dummy): pip install virtualenv-clone
      
    3. To duplicate venv1 to venv2:

      (venv_dummy): virtualenv-clone venv1/ venv2/
      
    0 讨论(0)
  • 2020-12-07 08:36

    Another option is to use virtualenv-clone package:

    A script for cloning a non-relocatable virtualenv.

    0 讨论(0)
提交回复
热议问题