What Parts Of A Virtualenv Need To Be Changed To Relocate It?
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. Howev
Solution 1:
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
Solution 2:
For your virtual environment directory {ENV} follow these steps
- Run
$ virtualenv --relocatable {ENV} - Edit
{ENV}/bin/activate, using vim or editor of your choice - Edit
VIRTUAL_ENV(around line ~42!)to match the new directory location
So 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
Solution 3:
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:
- the virtualenv activation scripts
- shebang lines in scripts in the virtualenv
bin/directory - absolute paths stored in .pyc files
- symlinks in any
local/directory

Post a Comment for "What Parts Of A Virtualenv Need To Be Changed To Relocate It?"