Here is a reference to have a local installation of python, only useful as a user without root privileges. Of course, a proper installation using the given GNU/Linux package manager is highly recommended, if enough privileges can be obtained to operate on the system. Full python installations are also available, e.g., Anaconda, and should be considered before taking the steps described below.

Contents

  1. Installation
    1. Scipy
    2. Matplotlib

Installation

Create a local folders for libraries and executables
mkdir ~/.local Download python source files, e.g.,
wget https://www.python.org/ftp/python/2.7.8/Python-2.7.8.tar.xz
Untar into ~/src and enter the new python folder.

Configure the python installation
./configure --prefix=$HOME/.local
At this point one can install with
make
make install

Verify that the folders ~/.local/lib/python2.7/site-packages/ and ~/.local/bin/python2.7/ have been created. Finally export the new python path and add an alias in ~/.bashrc
PYTHONPATH="${PYTHiONPATH}:$HOME/.local/lib/python2.7/site-packages/"
export PYTHONPATH
alias python=$HOME/.local/bin/python2.7

Logout the shell. When login again, check the installation with
python --version
Now Python is installed. Let's then proceed to install modules, e.g. Numpy. Download the source files, and copy them in ~/src. Extract and enter the folder. Install the module
python setup.py install --prefix=~/.local
Exit the module source files folder, and verify the installation by checking that
cd ~/
python -c "import numpy"
gives no error. The module is then installed. Proceed similarly for other modules, like scipy, Cython, ipython, matplotlib.

Scipy

Scipy requires the installation of Blas and Lapack libraries, which may also need to be installed locally. To install Blas: mkdir -p ~/src/
cd ~/src/
wget http://www.netlib.org/blas/blas.tgz
tar xzf blas.tgz
cd BLAS

## 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
export BLAS=~/src/BLAS/libfblas.a
To install Lapack:
mkdir -p ~/src
cd ~/src/
wget http://www.netlib.org/lapack/lapack.tgz
tar xzf lapack.tgz
cd lapack-3.5.0/
cp INSTALL/make.inc.gfortran make.inc # on Linux with lapack-3.2.1 or newer
Then modify make.inc with the following compilation options
OPTS = -O2 -fPIC
NOOPT = -O0 -fPIC

Now install the library:
make lapacklib
make clean
export LAPACK=~/src/lapack-3.5.0

The export options may be added to ~/.bashrc. Finally, to install scipy, enter the source file directory
python setup.py install --user
and check that the following gives no errors
cd ~/
python -c "import scipy"

Scipy should then be installed locally.

Matplotlib

Download matplotlib source files. Make sure all the dependencies are installed, in particular: python, numpy, libpng and freetype. For the first two requirement see the description above, while we describe here the remaining dependencies.

To install freetype download the source files. Once extracted, enter the source directory and install locally:
./configure --prefix=$HOME/.local/
make
make install

The same for to install libpng, download the source files and install locally:
./configure --prefix=$HOME/.local/
make check
make install

Finally, add the local executable and library paths to the standard ones in ~/.bashrc:
export PATH=/usr/local/bin:$HOME/.local/:$PATH
export LD_LIBRARY_PATH=~/.local/lib/:$LD_LIBRARY_PATH

Having installed all the dependencies, enter matplotlib source directory and install locally as usual:
python setup.py build
python setup.py install --prefix=~/.local/

Refs:

Back to top