Monday, April 30, 2012

virtualenvwrapper on Ubuntu 12.04

If you use Ubuntu, you were probably pretty excited when you turned on your machine this week and a window popped up asking if you'd like to upgrade to Precise Pangolin.

Of course there are many new things to explore. After I upgraded, one thing I noticed, is that is not in /usr/bin or anywhere in /usr/lib/python2.7 actually it's in /etc/bash_completion.d/virtualenvwrapper. It seems as if this script has actually bounced around a fair bit. In Ubuntu 9.04 it was in /usr/local/bin/virtualenvwrapper_bashrc. And of course it depends on how you installed it. If you used pip then it will install in /usr/local/bin (also see this), as if you were on a generic Linux (non-Debian) box.

Update (2012-05-01): See the source on Launchpad for yourself:

In contrast to the information in
/usr/share/doc/virtualenvwrapper/en/html/index.html this package installs as /etc/bash_completion.d/virtualenvwrapper.
Virtualenvwrapper is enabled if you install the package bash-completion and
enable bash completion support in /etc/bash.bashrc or your ~/.bashrc.
If you only want to use virtualenvwrapper you may just add
 source /etc/bash_completion.d/virtualenvwrapper
to your ~/.bashrc.

One of the implications of this is that the first time you start your terminal after instlalling virtualenvwrapper, it will run the virtualenvwrapper shell script in your bash completion directory. If you have not already set up a $WORKON directory, it will automatically set this to ~/.virtualenvs. It doesn't set the $PROJECT_HOME variable though. You can still add export WORKON_HOME=/path/to/your/virtualenvs to your .bashrc, .profile, .bash_profile, etc. (whichever applies to you). But it is obviously not necessary to add source /path/to/, since this file doesn't exist! And the virtualenvwrapper shell script will automatically run every time you start your terminal already because it is in the bash completion folder which is called indirectly from your global bashrc file (might be bash.bashrc or something else). file in /etc. Because .virtualenvs starts with a dot, Ubuntu will probably hide it so use control-H to reveal hidden folders and files in your file browser (probably Nautilus) or la (ls -A) in the terminal.

The upshot of this, is unless you want to set a project folder for virtualenvwrapper, you can start using it the instantly without any setup or murky .bashrc edits. Enjoy!
Fork me on GitHub