Install numpy in Python virtualenv Install numpy in Python virtualenv numpy numpy

Install numpy in Python virtualenv


The problem is SystemError: Cannot compile 'Python.h'. Perhaps you need to install python-dev|python-devel.

so do the following in order to obtain 'Python.h'

make sure apt-get and gcc are up to date

sudo apt-get update    sudo apt-get upgrade gcc

then install the python2.7-dev

sudo apt-get install python2.7-dev

and I see that you have most probably already done the above things.

pip will eventually spit out another error for not being able to write into /user/bin/blahBlah/dist-packages/ or something like that because it couldn't figure out that it was supposed to install your desiredPackage (e.g. numpy) within the active env (the env created by virtualenv which you might have even changed directory to while doing all this)

so do this:

pip -E /some/path/env install desiredPackage

that should get the job done... hopefully :)

---Edit---

From PIP Version 1.1 onward, the command pip -E doesn't work. The following is an excerpt from the release notes of version 1.1 (https://pip.pypa.io/en/latest/news.html)

Removed -E/--environment option and PIP_RESPECT_VIRTUALENV; both use a restart-in-venv mechanism that's broken, and neither one is useful since every virtualenv now has pip inside it. Replace pip -E path/to/venv install Foo with virtualenv path/to/venv && path/to/venv/pip install Foo


If you're on Python3 you'll need to do sudo apt-get install python3-dev. Took me a little while to figure it out.


If you're hitting this issue even though you've installed all OS dependencies (python-devel, fortran compiler, etc), the issue might be instead related to the following bug:"numpy installation thru install_requires directive issue..."

Work around is to manually install numpy in your (virtual) environment before running setup.py to install whatever you want to install that depends on numpy.

eg, pip install numpy then python ./setup.py install