6

I have a relatively big project that has many dependencies, and I would like to distribute this project around, but installing these dependencies where a bit of a pain, and takes a very long time (pip install takes quite some time). So I was wondering if it was possible to migrate a whole virtualenv to another machine and have it running.

I tried copying the whole virtualenv, but whenever I try running something, this virtualenv still uses the path of my old machine. For instance when I run

source activate
pserve development.ini 

I get

bash: ../bin/pserve: /home/sshum/backend/bin/python: bad interpreter: No such file or directory

This is my old directory. So is there a way to have virtualenv reconfigure this path with a new path?

I tried sed -i 's/sshum/dev1/g' * in the bin directory and it solved that issue. However, I'm getting a different issue now, my guess is that this sed changed something.

I've confirmed that I have libssl-dev installed but when I run python I get:

E: Unable to locate package libssl.so.1.0.0
E: Couldn't find any package by regex 'libssl.so.1.0.0'

But when I run aptitude search libssl and I see:

i A libssl-dev        - SSL development libraries, header files and documentation

I also tried virtualenv --relocatable backend but no go.

Braiam
  • 1
  • 11
  • 47
  • 78
Stupid.Fat.Cat
  • 10,755
  • 23
  • 83
  • 144
  • possible duplicate of [Renaming a virtualenv folder without breaking it](http://stackoverflow.com/questions/6628476/renaming-a-virtualenv-folder-without-breaking-it) – jb. Jan 25 '14 at 10:16

3 Answers3

2

Export virtualenvironment

from within the virtual environment:

pip freeze > requirements.txt

as example, here is for myproject virtual environment:
enter image description here

once in the new machine & environment, copy the requirements.txt into the new project folder in the new machine and run the terminal command:

sudo pip install -r requirements.txt

then you should have all the packages previously available in the old virtual environment.

Arthur Zennig
  • 2,058
  • 26
  • 20
0

When you create a new virtualenv it is configured for the computer it is running on. I even think that it is configured for that specific directory it is created in. So I think you should always create a fresh virtualenv when you move you code. What might work is copying the lib/Pythonx.x/site-packages in your virtualenv directory, but I don't think that is a particularly good solution.

What may be a better solution is using the pip download cache. This will at least speed up the download part of pip install. Have a look at this thread: How do I install from a local cache with pip?

Community
  • 1
  • 1
espensb
  • 29
  • 1
0

The clean way seems to be with virtualenv --relocatable.

Alternatively, you can do it manually by editing the VIRTUAL_ENV path in bin/activate to reflect the changes. If you choose to do so, you must also edit the first line (#) of bin/pserve which indicates the interpreter path.

Ullullu
  • 487
  • 4
  • 10