• 10

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191


File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

How to duplicate virtualenv

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 environment with the exact same packages but a newer version of Django. How can I do this?

      • 1
    • I would pip freeze all your requirements into a 'requirements.txt' file and create another virtualenv and run pip install requirements.txt
      • 2
    • If the python version of the virtual environment that you want to copy is different from your default python environment, you can setup the new environment as virtualenv -p /path/to/older/venv/bin/python new_venv and then use the requirements.txt that you generated after pip freeze

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:


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!

  • 182
Reply Report

Another option is to use virtualenv-clone package:

A script for cloning a non-relocatable virtualenv.

  • 29
Reply Report
      • 1
    • Hi, am i right to assume this allows me to copy a WHOLE python environment into a file. Then i would just have to load this file in a new computer/OS and i would get all my site packages installed back

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/
  • 4
Reply Report
      • 2
    • After I've cloned, my prompt in bash had the original environment name, because of the PS1 section within bin/activate

Can you not simply:

  • Copy the existing virtual env directory to a new one
  • Update to the new Django?
  • 1
Reply Report
    • On the other hand, changing bin/activate is quite a hack, and one must wonder if this can break stuff at some point. Especially when virtual environments are used in production settings.
      • 1
    • It does break a lot of things. It's easier to just recreate or clone the virtualenv. I tried to do just this (while waiting for a proxy server to open up so that I can reinstall all required packages and just start from scratch), and it ain't working! I thought I was being clever, but alas, it will take a lot of hacking to get this up and running, and honestly, there are much better things to do.

Trending Tags