Scientific Python on openSUSE

The Python programming language has a terrific and rapidly growing scientific ecosystem, and I'm currently using some of those tools to apply Support Vector Machines to neuroimaging data. Our neuroimaging lab uses openSUSE Linux, and getting the necessary Python packages installed proved to be a bit tricky. With some help from Stack Overflow, the problems were resolved, and I'm happily fitting models to data as I write this:

Library issues

As I mentioned, there were some hurdles to clear before I could get to hacking. Numpy and Scipy are the workhorses of any Scientific Python installation, and both take advantage of high-performance math libraries such as BLAS and LAPACK. Unfortunately, those libraries aren't installed by default in our lab, and our sysadmin was (reasonably) wary of disrupting systemwide settings by installing new packages. Happily, I was able to compile and install everything from source with lots of help and a few tweaks.

Here's the system information:

> cat /etc/SuSE-release
openSUSE 12.3 (x86_64)
VERSION = 12.3
CODENAME = Dartmouth

> uname -a
Linux somecomputer 3.7.10-1.40-desktop #1 SMP PREEMPT Thu Jul 10 11:22:12 UTC 2014 (9b06319) x86_64 x86_64 x86_64 GNU/Linux

And this is the Stack Overflow answer that got me started: http://stackoverflow.com/a/9173550/719469.

A few changes were necessary. First, we use a tcsh shell, so environment variables have to be set using a different format. Second, compile options had to be altered for our system. Details follow.

For BLAS:

mkdir -p ~/path/to/src/
cd ~/path/to/src/
wget http://www.netlib.org/blas/blas.tgz
tar xzf blas.tgz
cd BLAS

## NOTE: For openSUSE, I needed to edit a couple of lines in BLAC/make.inc before proceeding:
# -OPTS     = -O3
# -NOOPT    = -O2
# +OPTS     = -O2 -fPIC -m64
# +NOOPT    = -O0 -fPIC -m64

## NOTE: The selected fortran compiler must be consistent for BLAS, LAPACK, NumPy, and SciPy.
## For GNU compiler on 32-bit systems:
#g77 -O2 -fno-second-underscore -c *.f                     # with g77
#gfortran -O2 -std=legacy -fno-second-underscore -c *.f    # with gfortran
## OR for GNU compiler on 64-bit systems:
#g77 -O3 -m64 -fno-second-underscore -fPIC -c *.f                     # with g77
gfortran -O3 -std=legacy -m64 -fno-second-underscore -fPIC -c *.f    # with gfortran
## OR for Intel compiler:
#ifort -FI -w90 -w95 -cm -O3 -unroll -c *.f

# Continue below irrespective of compiler:
ar r libfblas.a *.o
ranlib libfblas.a
rm -rf *.o
setenv BLAS ~/path/to/src/BLAS/libfblas.a

For LAPACK:

mkdir -p ~/path/to/src/
cd ~/path/to/src/
wget http://www.netlib.org/lapack/lapack.tgz
tar xzf lapack.tgz
cd lapack-*/
cp INSTALL/make.inc.gfortran

# Again, for openSUSE the following changes to make.inc were necessary:
# -OPTS     = -O2 -frecursive
# -NOOPT    = -O0 -frecursive
# +OPTS     = -O2 -frecursive -m64 -fPIC
# +NOOPT    = -O0 -frecursive -m64 -fPIC

make.inc          # on Linux with lapack-3.2.1 or newer
make lapacklib
make clean
setenv LAPACK ~/path/to/src/lapack-*/liblapack.a

Pip pip

With BLAS and LAPACK installed, I was able to use a Python virtual environment to get all of the necessary packages installed. The pip utility is very handy for this purpose if you're on a Linux system. A few invocations of pip install later, I had Numpy, Scipy, and the rest of the tools that I needed in place to get on with my project.

Big thanks to Stack Overflow user “cfi” for his excellent answer to a complicated question!