Last Updated: February 25, 2016
·
868
· weslleymberg

Associating python's virtualenv with a project

Usually, when we are working on a project, its common that we create a specific virtual environment for it. But everytime we have to work on that project we do "workon my_env" and "cd path/to/project", well... virtualenvwrapper can make it simpler for you.

When creating a project with 'mkvirtualenv' you can use the option '-a' to associate your virtualenv with your project and everytime you activate your env you will be automaticaly redirected to your project's root. See how you can do it:

$mkvirtualenv -a path/to/my/project env_name

Or if you are already on your project's root:

$mkvirtualenv -a `pwd` env_name

If you already have an env to your project and want to associate one to another:

$echo "paht/to/my/project" >> ~/.virtualenvs/<my_env_name>/.project

Or simply:

$pwd >> ~/.virtualenvs/<my_env_name>/.project

If you are already on your project's root

Sources:
https://bitbucket.org/dhellmann/virtualenvwrapper-hg/pull-request/9/mkvirtualenv-a-virtualenv/diff
- http://mrcoles.com/tips-using-pip-virtualenv-virtualenvwrapper/