• 7

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 copy modules from one virtualenv to another

Is it possibe to copy python modules from one virtualenv to another.If so how is this done?

As long as you're moving them from one virtualenv to another on the same machine, you could easily just do:

$ cp -r [env1]/lib/pythonX.X/site-packages/* [env2]/lib/pythonX.X/site-packages/

However, if the environments are on different machines or utilizing different versions of python or some other major difference, it's probably not a good idea. In general it's much safer to generate a requirements.txt, and then use that to load up all the same modules in the other environment. You can create the file manually if you like, but it's easier to just use pip.

$ pip freeze -E [env1] > requirements.txt

Or, if your virtualenv is activated already, you can simply do:

$ pip freeze > requirements.txt

Then, in your other environment, you can do:

$ pip install -E [env2] -r /path/to/requirements.txt
  • 43
Reply Report
      • 1
    • The problem is not in the quantity of packages copied, but any differences in Python versions, system architectures, etc., between the source and destination. If source and destination are on the same machine, you should be fine; if they are on different machines, you should use pip freeze.

I am working on a 64bit machine with Ubuntu-14.04-64. I compiled and installed python-3.4.3 to /opt/python3.4/ and created a vitualenv based on this python.

mkvirtualenv -p /opt/python3.4/bin/python venv1

Also for ease:

sudo apt-get install virtualenvwrapper

With the venv installed and working with PyQt5 successfully (the hard bit) plus numpy, scipy, ipython etc. I installed virtualenv-clone:

workon myvenv
pip install virtual-clone

and then ran:

virtualenv-clone venv1 venv2

PyQt5 works this way. The command-line prompt still names venv1 as active but within ~/.virtualenv/venv2

cat activate* | grep "venv1"

shows 3 entries within the three files activate, activate.csh, and activate.fish

In activate, change

if [ "x(myvenv1) " != x ] ; then
        PS1="(myvenv1) $PS1"


        PS1="(myvenv2) $PS1"

In activate.csh change

if ("venv1" != "") then
        set env_name = "venv1"


    set env_name = "venv2"

In activate.fish change

if test -n "(venv1) "
        printf "%s%s%s" "(venv1) " (set_color normal) (_old_fish_prompt)


    printf "%s%s%s" "(venv2) " (set_color normal) (_old_fish_prompt)

Now when you source ~/.virtualenv/venv2/bin/activate or workon venv2 the command prompt will correctly display your environment (the cloned copy of venv1).

Edit: this doesn't answer the question "How to copy modules from one virtualenv to another" but I'm pretty sure the result is in many cases the desired one, namely the creation of a new venv based on a previously created one which includes (all of) the previously installed modules.

  • 2
Reply Report

seems like we can't just copy one virtualenv as another one. even you chnage the $VIRTUAL_ENV in the activate file, it still act as in origin virtualenv and pip will install all the packages to origin site-packages/

  • 1
Reply Report

Trending Tags