Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Copy complete virtualenv to another pc

Tags:

I have a virtualenv located at /home/user/virtualenvs/Environment. Now I need this environment at another PC. So I installed virtualenv-clone and used it to clone /Environment. Then I copied it to the other PC via USB. I can activate it with source activate, but when I try to start the python interpreter with sudo ./Environment/bin/python I get

./bin/python: 1: ./bin/python: Syntax Error: "(" unexpected 

Executing it without sudo gives me an error telling me that there is an error in the binaries format. But how can this be? I just copied it. Or is there a better way to do this? I can not just use pip freeze because there are some packages in /Environment/lib/python2.7/site-packages/ which I wrote myself and I need to copy them, too. As I understand it pip freeze just creates a list of packages which pip then downloads and installs.

like image 590
vicco Avatar asked Jan 25 '16 12:01

vicco


People also ask

Can I copy a virtual env?

We need to run the following command providing the path of the original virtualenv directory and the target directory. That is it. The new virtual environment will be cloned to the target directory. We can go to the target directory, activate the virtual environment, and get started.


2 Answers

Do the following steps on the source machine:

  1. workon [environment_name]
  2. pip freeze > requirements.txt
  3. copy requirements.txt to other PC

On the other PC:

  1. create a virtual environment using mkvirtualenv [environment_name]
  2. workon [environment_name]
  3. pip install -r requirements.txt

You should be done.

Other Resources:

  • How to Copy/Clone a Virtual Environment from Server to Local Machine
like image 106
Anuj Gupta Avatar answered Sep 27 '22 21:09

Anuj Gupta


I think what occurs is that you just copy the symbolic links in the source file to the target machine as binary files(no longer links). You should copy it using rsync -l to copy to keep those links.

like image 20
Lerner Zhang Avatar answered Sep 27 '22 20:09

Lerner Zhang