Here is a fast reference to have a local installation of python, mostly useful as a user without root privileges. Pre-built python distributions are also available, e.g., Enthought's Canopy, but we discourage the use of proprietary software since it restricts fundamental user freedoms.
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 withmake
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
Logout the shell. When login again, check the installation withPYTHONPATH="${PYTHiONPATH}:$HOME/.local/lib/python2.7/site-packages/"
export PYTHONPATH
alias python=$HOME/.local/bin/python2.7
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 thatcd ~/
python -c "import numpy"
gives no error. The module is then installed. Proceed similarly for other modules, like scipy of Cython, ipython, matplotlib.
To install Lapack:
The export options may be added to ~/.bashrc. Finally, to install scipy, enter the source file directory
To install freetype download the source files. Once extracted, enter the source directory and install locally:
The same for to install libpng, download the source files and install locally:
Finally, add the local executable and library paths to the standard ones in
Having installed all the dependencies, enter matplotlib source directory and install locally as usual:
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 optionsOPTS = -O2 -fPIC NOOPT = -O0 -fPICNow 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
python setup.py build
python setup.py install --prefix=~/.local/