Installing scipy in a Python virtual environment

Using virtualenv to create different python environments is a common practice while working in multiple projects. In addition, it may happen that we don’t have root access (i.e. admin rights) in the machine that we are using. Virtual environments are also quite useful in such situations. However, some python packages require extra dependencies that are not straightforward to install.

Installing scipy in a virtual environment should be initially quite straightforward:

python virtualenv.py myVE
source myVE/bin/activate
pip install scipy

However, during the installation of scipy I found the following three problems that took me several hours to solve. Here I share the solutions that worked for me in case they can be useful for someone else (specially myself in the future).

ImportError: libatlas.so.3: cannot open shared object file: No such file or directory
This error appears even having Atlas library properly installed. Apparently, it’s an error that only happens with numpy 1.9.2 in a virtual environment as I found in a small comment in Stack Overflow. The solution is to install the previous version:

pip install numpy==1.9.1

error: library dfftpack has Fortran sources but no Fortran compiler found
Despite my system had 3 different versions of gfortran, none of them were found by the installer. The solution is to create a symbolic link and then include it in your PATH variable.

ln -s /usr/bin/gfortran-4.7 ~/bin/gfortran
export PATH=$PATH:~/bin

ImportError: libopenblas.so.0: cannot open shared object file: No such file or directory
In this case, OpenBLAS library was not installed in the system, so the solution was to compile and install it manually. You can get the sources in the OpenBLAS website and then follow the installation guide.

make
make PREFIX=~/openblas install
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/openblas/lib
export PATH=$PATH:~/openblas/bin