I am trying to install the PyPy distribution of Numpy (Note that PyPy requires a different version of Numpy than that found in the repositories), but get the error:

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

I do however have the latest python-dev installed.

Any suggestions?

  • Is there a reason you are not using software center? Pypy is available in the repositories. Commented Sep 20, 2014 at 11:22
  • PyPy however requires a separate installation of Numpy. See here
    – Jonny
    Commented Sep 20, 2014 at 11:49
  • I see that and they are describing the installation from the standpoint of you installing from their downloads. Software center/apt-get will resolve dependencies so unless you require the version from the site it seems worth a shot to try software center, IMHO. Commented Sep 20, 2014 at 11:54
  • Yes but it does not work though. PyPy does not recognize the standard Numpy installation (I did try). I am more interested in why I am getting the error than in other ways of installing Numpy.
    – Jonny
    Commented Sep 20, 2014 at 11:56
  • Are you using 14.04? I wonder if it is because there are 2 versions of python installed. I assumed you are doing the 2.7 versions. Did you install the right python-dev version? Commented Sep 20, 2014 at 12:33

9 Answers 9


The error is a bit misleading but the solution for me was to install pypy-dev (instead of python-dev).

  • I wanted to up-vote but found I already up-voted!! Commented Sep 27, 2016 at 14:02
  • Perfect answer. I am commenting to highlight importance of this answer for other coming here.
    – PHcoDer
    Commented Sep 30, 2019 at 20:34

I noted this on their site:

Installing NumPy

NumPy is an exception to the rule that most packages work without changes. The “numpy” module needs to be installed from our own repository rather than from the official source.

If you have pip (the command-line assumes that it finds the pip belonging to PyPy, not the one from CPython):

pip install git+https://bitbucket.org/pypy/numpy.git

Alternatively, the direct way:

git clone https://bitbucket.org/pypy/numpy.git
cd numpy
pypy setup.py install

Note that NumPy support is still a work-in-progress, many things do not work and those that do may not be any faster than NumPy on CPython.

Installing More Modules

  • I saw yes. I think I should try to install pip!
    – Jonny
    Commented Sep 20, 2014 at 13:15
  • I wonder where this stands today, whether there's still a need, possibility or advantage to installing a PyPy distribution of numpy, if that's still a thing. Excuse my ignorance on PyPy parlance.
    – matanox
    Commented Feb 4 at 20:04

For anyone still facing this error in 2022, pip3 install --upgrade pip resolved the error for me.

  • Jesus, I would never have guessed. Commented Aug 23, 2022 at 11:58

Somebody mentioned portable PyPy which I maintain. The stable builds indeed don't have numpy precompiled but I also build unstable builds from time to time which include numpy. You can see them here: https://bitbucket.org/squeaky/portable-pypy-weekly/downloads.

  • Excellent thank you @Squaky, I will check it out!
    – Jonny
    Commented Sep 27, 2014 at 7:42

Here is another possibility. I found this going through their webpage. An alternate way to install (found off your link). portable binaries

When I mentioned versions, did you install python-dev or python3-dev?

  • Thanks. I downloaded it but have no Idea how to build it.
    – Jonny
    Commented Sep 20, 2014 at 12:49
  • Directions on page say: "The idea is that you just download an archive, uncompress it and run it instantly without installing any extra libraries or tweaking your OS. Currenly they are known to work across various DEB and RPM based distributions including RHEL/Centos 5 and later, Ubuntu and Debian stable." Extract it in your home directory and you should find all you need then. Commented Sep 20, 2014 at 12:53
  • 1
    Extract, go into pypy folder that extracted, then into bin (using terminal) then type ./pypy and it runs :) Option 2 use the full path to the pypy binary or if you added the resulting folder to your PATH you'd be able to type pypy. I just had it running. Commented Sep 20, 2014 at 12:58
  • Seems to work! Except the Numpy issue is still an issue (-:
    – Jonny
    Commented Sep 20, 2014 at 13:01
  • Hm, looking some more. Did you note this on their site? "Note that NumPy support is still a work-in-progress, many things do not work and those that do may not be any faster than NumPy on CPython." Commented Sep 20, 2014 at 13:10

In my case, i use virtual environment with base python3.9 interpreter, but system default is python3.8. So when i tried to install 'sudo apt install python3-dev' it use 3.8 python3-dev, but my environment need 3.9. Solution is change base python for virtual environment to system default 3.8.


In my case, I had to install python3-dev. If install python-dev it installed all for Python 2.7, which was the problem. So sudo apt install python3-dev should solve the problem


I met the same question while installing torch or numpy. the cmd was input was: pip install torch pip install numpy the environment of my computer is python3.8, ubuntu 18.04, pip version is 23.0.1, however I get a note in terminal of ubuntu, then a new installing method was tried and it worked fine: python -m pip install torch


I did all of suggestions that other users in this question made. But after few days of wild goose chase, I removed my virtual environment. It seems that opencv-python has non compatible dependency to torch so you have to make your own build of opencv then install torch. This was solution in my case.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .