For marketers
who love technology
Home » , » How to replicate / export a virtualenv from a machine to another ?

How to replicate / export a virtualenv from a machine to another ?

Sudo (Photo credit: Scelus' Comix)
If you code in Python, you probably use virtualenv to maintain a clean setup and avoid problems with different versions of pythons. But sometimes, you need to replicate / export a virtualenv from a machine to another. This post will explain you exactly how to do this.

First, use the following commands on the origin machine:

source ./bin/activate
pip freeze > requirements.txt

Then, copy your source code files from the virtualenv folder (called virtualenv_1) on the target machine. Do NOT copy the virtualenv files in folders such as bin, lib etc. We will eventually create these files with virtualenv on the new system:

sudo apt-get install python-virtualenv
sudo  virtualenv virtualenv_1

Then install all the required packages:

cd virtualenv_1
source bin/activate
sudo pip install -r requirements.txt

That's it! If you have liked this article, please put a link to it on your Google+  / facebook profile are any other kind of web site: it will help others find it in the search engines. Thanks!


About Gilles


  1. Your underlying assumption of python versions on both machines (source and target) being same does not serve the purpose of having a "replica" of the original virtual machine.

  2. Thank you for this post and Gaurang's comment on it. What if the target machine has done OS level system updates/upgrades or from a clean latest image? What are the additional steps within virtualenv (and possibly resulting system level packages). I'd assume that since the target machine is brought up with latest system image and packages, upward impact is zero, but the packages within virtualenv will need to be upgraded after the last your step: sudo pip install -r requirements.txt. I'm is this situation and would appreciate any help from the experts.

  3. Dear RAJPAN,
    Already found a solution?
    The "pip install -r requirements.txt" is not a solution... lots of erros...not found

  4. ran $pip install -r with vm active, and then pip freeze, list is empty. Also seems to skip some packages.


Spam / promotional comments will be deleted. Links ok only for "real" comments. Please refer to the legal notice of this blog in case of questions.

Note: Only a member of this blog may post a comment.