I've been using the Anaconda python package from continuum.io recently and found it to be a good way to get all the complex compiled libs you need for a scientific python environment. Even better, their conda tool lets you create environments much like virtualenv, but without having to re-compile stuff like numpy, which gets old very very quickly with virtualenv and can be a nightmare to get correctly set up on OSX.
The only thing missing was an easy way to switch environments - their docs suggest running python executables from the install folder, which I find a bit of a pain. Coincidentally I came across this article - Virtualenv's bin/activate is Doing It Wrong - which desribes a simple way to launch a sub-shell with certain environment variables set. Now simple was the key word for me since my bash-fu isn't very strong, but I managed to come up with the script below. Put this in a text file called conda-workon, make it executable (chmod 777), and put it on your path somewhere (you can put it in bin, personally I just have a scripts folder in my home directory that I add to my PATH). You also need to set an environment variable ANACONDA_WORKON_HOME. In my case I put
export ANACONDA_WORKON_HOME=$HOME/anaconda/envs
in my .bash_profile
It's pretty basic and I'm sure it could be improved in many ways, but I find it useful and I hope you do too!
EDIT: The latest Anaconda allows you to create Python3 environments. This approach works fine for these environments BUT you have to remember to use python3 and ipython3 instead of python and ipython.
This is a completely different style than
source activate
. You can specify a command to run rather than a shell. Even if you just create a subshell, you just exit instead ofsource deactivate
.The semantics are different too.
source activate
modifies the current process (shell).conda-workon
creates a different shell.