18

I created a virtualenv with pypy and tried to install scipy, but installation ended with the following error:

distutils.errors.DistutilsError: Setup script exited with error: Command "cc -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -O2 -fPIC -Wimplicit -DHAVE_NPY_CONFIG_H=1 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -DNO_ATLAS_INFO=1 -DHAVE_CBLAS -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -Inumpy/core/include -Ibuild/src.linux-x86_64-3.2/numpy/core/include/numpy -Inumpy/core/src/private -Inumpy/core/src -Inumpy/core -Inumpy/core/src/npymath -Inumpy/core/src/multiarray -Inumpy/core/src/umath -Inumpy/core/src/npysort -I/home/luke/Programowanie/Python/connect4/venv-pypy/include -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -Ibuild/src.linux-x86_64-3.2/numpy/core/src/private -c numpy/core/src/multiarray/scalarapi.c -o build/temp.linux-x86_64-3.2/numpy/core/src/multiarray/scalarapi.o" failed with exit status 1

There is a specific numpy version suited for pypy, but the only thing I found about scipy is an old call for donations. Has anything changed since then?

hpaulj
  • 221,503
  • 14
  • 230
  • 353
Luke
  • 1,369
  • 1
  • 13
  • 37
  • `scipy` has compiled code, just as `numpy` does. So even if you have a PyPy numpy working (is it fully compatible?), that does not mean you can install regular `scipy` on top of it. If you did not find a PyPy `scipy`, then you can't add it. But keep in mind that `scipy` is a collection of loosely connected packages. – hpaulj Jan 11 '16 at 20:07
  • 1
    That call for donations is for the `numpy proposal`. That proposal specifically excludes `scipy`. In other words, no one is officially working on a `scipy` version. – hpaulj Jan 11 '16 at 21:53
  • @hpaulj They mention scipy later in the text: "Specifically, we don't plan to (...) implement other scientific libraries, like SciPy, matplotlib or biopython" – Luke Jan 12 '16 at 08:17

5 Answers5

24

Yes, it is possible, starting from Scipy 1.1.0. New enough PyPy (>= 6.0.0) and Numpy are however required, numpy>= 1.14.3, and preferably numpy>=1.15.0 when it's released. Installation can be done via the usual

pypy3 -mpip install numpy
pypy3 -mpip install scipy

assuming you have BLAS/LAPACK installed, so first you should make sure you are able to install numpy/scipy on normal Python from sources.

Nobody probably has tried whether this works with Pypy on Windows, so you are on your own there. It also probably won't work with NumPyPy --- you need the vanilla Numpy.

The other answers say "No" since that was the situation before May 2018.

pv.
  • 33,875
  • 8
  • 55
  • 49
  • As of today, you have to also install pybind11; however, things still break with a pybind error: /usr/local/include/detail/common.h:134:19: fatal error: cstddef: No such file or directory. – weberc2 Feb 04 '20 at 23:19
  • For scipy, I had to install some dependencies like `sudo apt install gfortran libatlas-base-dev libopenblas-dev pypy3-dev`, however, it still failed to build. – Amin Ya Feb 10 '23 at 22:26
8

No. SciPy has bits and pieces talking to cpython's C API, and pypy does not support that.

EDIT: As of May 2018, this is incorrect, and scipy is pypy-compatible. See the answer by @pv. for details.

aph
  • 225
  • 3
  • 12
ev-br
  • 24,968
  • 9
  • 65
  • 78
7

Seems that the link in @piv.s great answer does not contain what is needed anymore. For installing BLAS/LAPACK and avoiding installation errors such as NotFoundError: no lapack/blas resources found on Ubuntu first run:

sudo apt-get install libatlas-base-dev

Then using the pip that corresponds to your pypy (not the system's):

pip install numpy
pip install scipy

or the one mentioned by piv. will do the trick.

Farzad Vertigo
  • 2,458
  • 1
  • 29
  • 32
2

No, but miraculously, matplotlib happens to work with pypy, both in jupyter notebook and as a standalone version (through wx widgets).

So it isn't that impossible.

Antony Hatchkins
  • 31,947
  • 10
  • 111
  • 111
2

As of this writing, numpy and scipy are installable with PyPy through pip, but there's a catch: if you're going to run that within a virtualenv (which you probably should), remember to create the virtualenv with "--always-copy", otherwise virtualenv will create a symlink for the "include" dir, making it read-only for the user, which will break the installation for pybind11 (which is a dependency for scipy).