Python virtualenv and virtualenvwrapper with scientific packages, the simple way

During a course on scientific programming in python, we were pointed to a nice linux script to get virtualenv and virtualenvwrapper installed with nice option for upgrading the environment in one command.
Virtualenv allows you to generate sandboxed python environment where you can experiment and install different python interpreters with their own packages that don’t interfere with your system python setup. This tutorial requires some packages and their respective development headers to be install with the root account. I have not had time to look into doing this with your regular account, which would be nice on a server where you are not given root access. But for now, to install:

user@host $ curl -s https://raw.github.com/brainsik/virtualenv-burrito/master/virtualenv-burrito.sh | $SHELL

This executes the shell script virtualenv-burrito.sh and sets up virtualenv and virtualenvwrapper for your local user. You should close and reopen terminal and see if virtualenvwrapper has been sourced. Test:

user@host $ mkvirtualenv -h

If it doesn’t work, fix your .bashrc, .bash_profile and .profile setup as suggested on the github link. Now:

user@host $ mkvirtualenv test

Now your prompt should look like:

(test) user@host $

Which indicates you are working in the test environment. You can leave that environment with the command deactivate, and you can enter the environment with workon:

(test) user@host $ deactivate
user@host $ workon test
(test) user@host $

In your new environment usually very few packages are installed after initialization. You can use pip to install new packages. Lets start with common system dependencies for some of the usual python packages and then use pip to install the python packages:

(test) user@host $ sudo apt-get install libblas3 libblas-dev liblapack3 liblapack-dev libfreetype6 libfreetype6-dev libpng12-dev libpng++-dev libzmq-dev gfortran gcc g++ python-qt4 python-dev build-essential
(test) user@host $ pip install numpy scipy matplotlib pandas scikit-learn biopython
(test) user@host $ pip install ipython[zmq,qtconsole,notebook,test] --upgrade

Given you have resolved all system dependencies. If this fails, install packages one by one and figure out what is missing. To test that the ipython notebook is working with matplotlib inline plotting, run this command:

(test) user@host $ ipython notebook --pylab=inline

and in the first cell do:

plot(range(10),range(10))

Which should put a plot in the notebook. To update the virtualenv and virtualenvwrapper, the script we installed provides a nice command to upgrade:

user@host $ virtualenv-burrito upgrade

Binni out!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s