virtualenvs info gotchas - RichardForshaw/dev-tools-blog GitHub Wiki
VirtualEnv is a virtual environment manager for developing python projects. It allows you to create isolated python environments so you can work on multiple project without getting your packages and dependencies tangled. VirtualEnvWrapper is a set of extensions to this module which aligns the functions to your development workflow.
Essentially:
- Create a new environment with
mkvirtualenv
- Make sure you are working on your env with
workon \<myenv\>
- Install packages with pip
- Show the packages you are using with
lssitepackages
- Exit your environment with
deactivate
- Make sure you install both virtualenvwrapper with
apt-get
andpip install
- Make sure you put
source /<location>/virtualenvwrapper.sh
in your .bashrc - Make sure you put
/usr/lib/<pythonlocation>/dist-packages/
in yourPYTHONPATH
before running any virtualenv commands - If you have recently upreaded python from less than version 2.7.6, make sure you do the following:
- Make sure you have the right pip!!. Python >2.7.5 comes with its own pip, so you will need to uninstall the 'external' pip:
sudo apt-get remove python-pip
- Make sure you have the latest PIP running (i.e. the one from your upgrade). If not, run
easy_install pip
- Make sure you have the latest virtualenvwrapper python libraries:
pip install virtualenvwrapper
orpip install -U virtualenvwrapper
. Virtualenvwrapper needs the shell scripts AND the python libraries. If not when it makes the new environment it won't install you latest python version in the environment and you will get all sorts of installation headaches.
Similar to VirtualEnv but for managing your command shell environment. It allows you to put a ".env" file in a directory which defines the environment specification for working in that directory and subdirectories.
Installation Gotcha: The documentation fails to mention that it installs a script to /usr/local/bin/activate.sh
which you need to reference in your bashrc. If you don't do this it won't work!!!
Usage Gotcha: AutoEnv overrides the cd
command, so if you rely on your own override be careful. It also means that it might not work for pushd/popd. I've not tested this yet. It also only invokes environment changes when it encounters a ".env" file, so if you cd up and out of that directory, it does not deactivate the environment!!!