21

I've created virtualenv for Python 2.7.4 on Ubuntu 13.04. I've installed python-dev.

I have the error when installing numpy in the virtualenv.

Maybe, you have any ideas to fix?

4
  • 1
    Have you installed liblapack-dev and libblas-dev? Commented Sep 13, 2013 at 12:14
  • No. I've installed these packages on my Ubuntu, but when installing I still have the same error. Commented Sep 13, 2013 at 12:32
  • Which pip/virtualenv versions you are using (pip --version/virtualenv --version)? Also check you have python2.7-dev installed (it should have been installed with python-dev, but would be better to check) Commented Sep 13, 2013 at 13:59
  • pip 1.4.1 and virtualenv 1.10.1. python2.7-dev package has already been installed. Commented Sep 13, 2013 at 19:27

7 Answers 7

29

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

Sign up to request clarification or add additional context in comments.

1 Comment

THanks a lot !! This worked for me like a charm and I have been struggling with error for a while now.
20

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.

Comments

13

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

Comments

4

This answer is for those of us that compiled python from source or installed it to a non standard directory. In my case, python2.7 was installed to /usr/local and the include files were installed to /usr/local/include/python2.7

C_INCLUDE_PATH=/usr/local/include/python2.7:$C_INCLUDE_PATH pip install numpy

Comments

4

I recently had the same problem. I run Debian Jessie and tried to install numpy from a Python 2.7.9 virtualenv. I got the same error -- numpy complaining that Python.h is missing while python2.7-dev and gcc are already installed.

File "numpy/core/setup.py", line 42, in check_types
],
File "numpy/core/setup.py", line 293, in check_types

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

I'm running pip 1.5.6 and it doesn't appear to have command line option '-E'

$ pip -V
pip 1.5.6 from /home/alex/.virtualenvs/myenv/local/lib/python2.7/site-  packages (python 2.7)

Upgrading pip to the latest verson 7.0.3 solves the problem

$ pip install --upgrade pip
Downloading/unpacking pip from https://pypi.python.org/packages/py2.py3/p/pip/pip-7.0.3-py2.py3-none-any.whl#md5=6950e1d775fea7ea50af690f72589dbd
Downloading pip-7.0.3-py2.py3-none-any.whl (1.1MB): 1.1MB downloaded
Installing collected packages: pip
Found existing installation: pip 1.5.6
Uninstalling pip:
  Successfully uninstalled pip
Successfully installed pip
Cleaning up...

Now it is possible to install numpy

$ pip install numpy
Collecting numpy
Downloading numpy-1.9.2.tar.gz (4.0MB)
100% |████████████████████████████████| 4.0MB 61kB/s
Installing collected packages: numpy
Running setup.py install for numpy

Successfully installed numpy-1.9.2

Comments

2

This is probably because you do not have the python-dev package installed. You can install it like this:

sudo apt-get install python-dev

You can also install it via the Software Center:

enter image description here

Comments

2

@samkhan13 solution didn't work for me as pip said it doesn't have the -E option. I was still getting the same error, but what worked for me was to install matplotlib, which installed numpy.

1 Comment

thanks for pointing that out. i've made an edit to the answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.