Using PyPy as an Interpreter with PyCharm

Viewed 1727

Overview:

I have a project with two existing Virtualenv environments. One uses CPython 3.7 and one uses CPython 3.8. I want to add another interpreter that uses PyPy. Currently, I have Python 3.8 specified as my PATH python executable. I'm running PyCharm Professional 2020.3 on Windows 10.

Working CPython Workflow:

I go to "Settings", "Project: xx", "Python Interpreter". Then, under the drop-down menu, I selected "show all". Then I clicked the plus sign, and under "Virtualenv Environment" listed a new folder name in the project directory for the "Location", and navigated to one of my python executables for the "Base Interpreter". I then click "OK", and PyCharm creates a new Virtualenv for me.

Attempted PyPy Workflow:

I first downloaded and extracted PyPy to my desktop from the link highlighted below, which is found here. enter image description here I then copied the extracted folder to my C:\\Users\xx\AppData\Local\Programs\ folder so it was in the same place as the rest of my Python interpreters. Then, I tried to replicate the CPython workflow to set up a PyPy Virtualenv environment. This failed, as, after the last step, Python generates the following error message:

Error: Command '['C:\\Users\\xx\\Documents\\GitHub\\xx\\venvTest\\Scripts\\pypy3.exe', '-Im', 'ensurepip', '--upgrade', '--default-pip']' returned non-zero exit status 2.

I didn't understand this error, so I looked around and found this question which links to the documentation. It seems like PyPy can only be used as a system interpreter with PyCharm. So, I tried to go to "Settings", "Project: xx", "Python Interpreter". Then, under the drop-down menu, I selected "show all". Then I clicked the plus sign, and under "System Interpreter", I navigated to my "pypy3.exe" file for the "Interpreter". I then click "OK", and PyCharm created a new interpreter for me.

PyPy Interpreter Issues:

Now, in "Settings", "Settings", "Project: xx", "Python Interpreter" I've selected the PyPy interpreter from the drop-down menu. A warning appeared that I don't have the python packaging tools installed, so I clicked the link to install them. They install and I am greeted with the following packages: enter image description here Everything is okay so far, so I click the plus sign, search for NumPy, and attempt to install it. Then, PyCharm starts to install it, and I notice that is taking forever. Lo and behold, after about 15 minutes, the install fails with the following error:

ERROR: Command errored out with exit status 1: 'C:\Users\xx\AppData\Local\Programs\pypy3.7-v7.3.3-win32\pypy3.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\xx\\AppData\\Local\\Temp\\pip-install-wx4cbjwv\\numpy_bf6ea1d419434c2e9caea46adf58b45c\\setup.py'"'"'; __file__='"'"'C:\\Users\\xx\\AppData\\Local\\Temp\\pip-install-wx4cbjwv\\numpy_bf6ea1d419434c2e9caea46adf58b45c\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\xx\AppData\Local\Temp\pip-record-y9bh74bh\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\xx\AppData\Local\Programs\pypy3.7-v7.3.3-win32\include\numpy' Check the logs for full command output.

I don't know how to interpret this command, and I have no idea how to proceed.

Updated Attempts:

As per jupiterbjy's answer, I tried repeating my process with the 3.6 release of PyPy. It produced identical results as 3.7 when I tried to make it a virtualenv environment or a system interpreter.

2 Answers

As the PyPy release manager, I disagree with @jupiterbjy. Please use PyPy 3.7, the 3.6 version is being phased out.

The reason it took a long time to install NumPy is that it is compiling from source: NumPy does not at this time make binary packages (called "wheels" in Python) available for PyPy on windows. It does have them for Linux.

Your best bet for using NumPy with 32-bit PyPy on windows is to manually install the pre-compiled wheel from https://www.lfd.uci.edu/~gohlke/pythonlibs/#numpy. To do this you should install the numpy‑1.20.1+mkl‑pp37‑pypy37_pp73‑win32.whl which is the one built for PyPy3.7.

If NumPy is all you need, maybe you can manage. But do not expect NumPy programming to be faster with PyPy, it is written using the C-API which slows PyPy down.

We have much better ecosystem support from conda and linux, if you use the Windows internal Linux support via WSL you will find that most of the binary packages are supported with not need to compile them.

If you used pypy3.7 try using pypy3.6 instead, with using pip module directly from whatever terminal you are using.

pypy3 -m pip install numpy
C:\pypy3.6-v7.3.3>pypy3 -m pip install numpy
Collecting numpy
  Downloading numpy-1.19.5.zip (7.3 MB)
     |################################| 7.3 MB 6.4 MB/s
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
    Preparing wheel metadata ... done
Building wheels for collected packages: numpy
  Building wheel for numpy (PEP 517) ... done
  Created wheel for numpy: filename=numpy-1.19.5-pp36-pypy36_pp73-win32.whl size=4511302 sha256=7a7b77a0d820f96200eec66e1bc8e8e05c61bf2591689ad6fdcb
2a002b265176
  Stored in directory: c:\users\jupiterbjy\appdata\local\pip\cache\wheels\97\ac\fc\fbf42c6cd047a8f16c5dba00480027d4e566f8ca8a34e79ad6
Successfully built numpy
Installing collected packages: numpy
  WARNING: The script f2py.exe is installed in 'C:\pypy3.6-v7.3.3\Scripts' which is not on PATH.
  Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed numpy-1.19.5

I also failed to install by whatever means with pypy3.7 - Since 3.7 is still in development which is based on 3.6, it might not be as compatible as you'd expect.

If use of 3.7 is mandatory, you might need to check out this official docs for other official pypy compatible numpy branches/repos - but I doubt if this can satisfy the dependencies of other numpy-dependent modules.

Related