Installing Numpy in Ubuntu 11.04 From Source


In order to obtain the Numpy package, you’ll want to go to their website. Once you’re there you can download the source files. It’s also important to note that there are detailed Numpy installation instructions here. I’m just describing my experience.


Because Numpy is a tool that requires Python…you’re going to need Python. If you’re using Ubuntu 11.04 and have not yet installed Python (or want to re-install a different version), I have a guide for that here.


I moved my source file to a place where I wanted to unpack it. In my case, I’ve made a local installation of Python, and I plan on making a local installation of Numpy. So let’s say I’m unpacking in:

$ mv numpy-1.6.1rc1 ~/opt
$ tar -xzvf numpy-1.6.1rc1.tgz
$ rm numpy-1.6.1rc1.tgz

What this will do is move my Numpy source tarball into my desired source directory, unpackage it, and then remove the undesired source tarball. I usually keep a back-up of my source for a while. You can always download the source again later if you want, I just like having it in case I can’t access the internet for some reason, or if I’m installing on a machine that I’m accessing through ssh.


Here is where your installation of Python will service you. Python takes files that you’ll typically see in source directories and executes the code. In the case of Numpy, you’ll issue this command from the source directory.

$ python build

Now here’s where the fun starts. Numpy has a lot of options. I’m only going to address a select few and make you aware of others. If optimization is your interest, you’ll want to check out the options in the site.cfg file so that you can configure ATLAS or BLAS. They’re not necessary and I have not tested their effectiveness. But they are widely used in the field of scientific computing and I highly recommend them!

I’m also going to be using the Intel compilers. That’s a link for instruction provided by the SciPy folks themselves! I chose these options when configuring my build:

$ python build –fcompiler=intel –compiler=intel build_clib –compiler=intel build_ext

I specified both the Intel C and Fortran compilers. There are two steps to this process. The first is the build, the second is the install.


Once you have completed your Numpy build, it’s time to install. This is the command I used.

$ python install –prefix=/home/ben/opt/Python-2.7.2./

This is curious for several reasons. As a new user, when I’d typically run configure (from the world of make files), I felt that setting prefixes (which set the installation directory) would go into the configure step. But python does things a little differently. The ‘configure’ step doesn’t really have a true analog with Python build and install. We specify the installation directory during install!

Notice that I also installed Numpy in the location of my Python installation. The binaries from the installation end up joining my Python binaries. Now, if you followed this tutorial, you’ll notice that you can just type

$ which f2py

from the command line after installation and see that it is in your path! This is because I installed Numpy where Python is installed. Similar to Python, the Numpy executable ‘f2py’ is in $INSTALL_DIR/bin. If you didn’t use the tutorial, no worries! You would adjust your PATH variable similarly as I described in the tutorial, regardless of your installation directory. There is a lot of documentation out there on modifying your PATH if you still have questions. But I highly recommend using the same location as your Python installation. You may have to make some path adjustments if they are different!

Now that f2py is installed and your PATH is configured, try running Python.

$ python
>>> import numpy

If you can successfully import Numpy, you’re almost in business! Start looking for examples to run and get started! If you can pass tests, you can start the really exciting stuff!


Leave a Reply

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

You are commenting using your 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