So, I've got a Python program with a ridiculous number of addons/packages. I'd like to be able to distribute the program in its virtualenv, so that the packages come bundled. However, the program is for Windows, and the "relocatable" feature of virtualenvs is unsupported on Windows (as well as still being experimental).
So, I'm looking at either writing a script, or just writing instructions to manually change absolute path names to relocate the virtualenv.
My question is if anybody knows where all I'd have to look for absolute path names in the virtualenv. I'm pretty new to Python packaging. The activate.bat script contains absolute path names, but do individual packages have absolute pathnames hard-coded into their installations?
The section Making Environments Relocatable describes why a virtualenv can't be simply moved, but doesn't list the places that contain absolute path names.
Rather than trying to do this manually, you'd be better off using the freeze
option to pip
to create a requirements file. You can now rebuild your entire virtualenv with a single command.
On old virtualenv:
pip freeze > stable-req.txt
On the new one:
pip install -r stable-req.txt
For your virtual environment directory {ENV}
follow these steps
$ virtualenv --relocatable {ENV}
{ENV}/bin/activate
, using vim or editor of your choiceVIRTUAL_ENV
(around line ~42!)to match the new directory locationSo if you are looking to write a script, you can either export VIRTUAL_ENV
shell variable or perform the edit on /bin/activate dynamically.
This is how I've setup mine.
# env/bin/activate BIN_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" # virtual env is at ./env ENV_DIR=`dirname $BIN_DIR` VIRTUAL_ENV=$ENV_DIR export VIRTUAL_ENV
virtualenv-tools is a script to update an existing virtualenv's location after you move it. While it doesn't help on Windows, it might be useful to others.
It updates:
bin/
directorylocal/
directoryIf you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With