Issue
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.
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:
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.
Solution
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.
Answered By - mattip