Tag Archives: scientific programming

Scientific Python…the easy way

tl;drUse Anaconda

The scientific programming libraries available for Python are among the best available out there. Libraries such as scipy, scikit-learn and scikit-image the among the easiest to use that I have come across. Of course much of that is due to the fact that Python is an amazing language…but we won’t get into that in this post.

Using the any of these libraries is dead easy once you get the hang of Python. The documentation is also (usually) pretty good. However, installing the libraries and their dependencies can be a pain in the ass. Most of these libraries are updated pretty frequently so you really want to use the latest version at anytime. So while the Debian repository has most of the packages you would need (not sure about other distros), the versions on the repository is usually outdated (with good reason).

One option (for Debian users at least) is neurodebian but I have had some problems with neurodebian in the past. My initial solution was to install as many as of the dependencies as possible from the Debian repositories and using pip for the latest versions of the different libraries. This works fine in most cases. Problem is, when you want to upgrade to newer versions keeping track of how you installed each library, deciding what to upgrade, etc. becomes a pain (which is why we have apt-get…but we’ve already established that we can’t do that).

The next best solution that I have come across is Anaconda from Continuum Analytics. Anaconda installs everything you need for scientific programming in Python (including Python itself) within a directory anywhere on your machine. Works on Mac, Windows and Linux (any distro as far as I know) and is really simple to install. It even comes with Spyder, a MATLAB-like IDE for Scientific Python programming (although I prefer Vim+terminal).

Installing Anaconda

For Mac and Windows, just download the GUI installer and follow the instructions…hard to mess up. For Linux systems, just download the shell script from http://continuum.io/downloads and run it to install anywhere on machine. If you’re installing it within your home directory (or anywhere else you have permissions) you won’t need root access. However, if you are planning on allowing multiple users to have access to Anaconda, I suggest the following approach.

  1. Install Anaconda in /etc/anaconda (you will probably need root access to do this)
    sudo bash installer.sh
    When asked if you want to install Anaconda in /root/anaconda enter /etc/anaconda instead
  2. Create a user group called anaconda
    sudo addgroup anaconda
  3. Next change the ownership of the /etc/anaconda directory
    sudo chown -hR root:anaconda /etc/anaconda
  4. Add the root user to the group anaconda
    sudo adduser root anaconda
  5. Now add any user needs access to Anaconda to the group anaconda. Make sure you use adduser instead of usermod to do this (usermod doesn’t work sometimes)
    sudo adduser username anaconda
  6. (optional) Check that the users were actually added to the group anaconda
    sudo groups username
  7. Finally for each of those users, add the following line to the end of their .bashrc file (usually found in /home/username/.bashrc) using a text editor of your choice
    export PATH="/etc/anaconda/bin:$PATH"
  8. Restart the machine (just in case)

That’s it! Just to see if everything is working fine, run Python. You should see something like the following in the first line.

Python 2.7.5 |Anaconda 1.6.1 (64-bit)| (default, Jun 28 2013, 22:10:09)

The important bit to lookout for is ...|Anaconda.... If you see that everything should be fine.

Notes:

  • I used /etc/anaconda but you can use anything you want really
  • I did this on a Debian 6.0 (squeeze) box. Should be the same for most other systems but just be careful
  • If you ever need to uninstall Anaconda just delete the directory /etc/anacondapiece of pie 🙂
  • If you need any help, first place to look is of course the Anaconda documentation. Otherwise, the Anaconda mailing list would be your best bet.
Tagged , ,