mrQWERTY
mrQWERTY

Reputation: 4149

Virtualenv not finding imported modules

I have a project that I packaged with virtualenv. It installed setuptools & pip fine and set up all the necessary folders. I than ran source bin/activate and installed the necessary libraries for my project: xmlutils, configparser.

I compressed the project folder into a zip and then tried to use it on another computer. I was able to run source bin/activate without problems. However, once I ran my script, the module xmlutils was not found. I dug into the "libs/site-packages" folder of the project and it is clearly there.

Is it because I have to install virtualenv on the other computer?

Here is the organization of my project with virtualenv set up:

project: bin include lib lib64 projectScript.py projectScript2.py

Upvotes: 2

Views: 2734

Answers (1)

Ffisegydd
Ffisegydd

Reputation: 53718

When constructing a virtualenv it is tied to a specific path meaning that you cannot rename it or move it. If you wish to create a movable virtualenv then you can use the --relocatable option as given in the docs here.

The command needed for making a virtualenv relocatable is:

virtualenv --relocatable ENV

Note two things:

  1. This is experimental and not guaranteed to work.
  2. The above command must be ran again if you add any new packages to the virtualenv.

Additionally (as I mentioned in a comment) you can use pip freeze > requirements.txt to save a text file containing all the package requirements from the pip inside your virtualenv. You can then install these packages in a new virtualenv using the command pip install -r requirements.txt.

Upvotes: 4

Related Questions