The Complete PyPy Guide
This is the complete guide to compiling PyPy. If your new, compiling from source can be very difficult, so i’ve written the steps. Each command you type into the terminal (or, console) is highlighted in a box. These commands are a darkish grayish, color.
First, download the sources from thesatellite.org/download/pypy-source-code
This will give you a package that you must extract, and inside you will find two source files: PyPy (Python) 2, and PyPy (Python) 3. These files are for Python 2 and Python 3. Because PyPy is written in Python 2, we must use a Python 2 interpreter to build PyPy 2 or 3. This means we must compile PYPY 2 first, to use it to build PyPy 3.
Firstly there are some requirements for building PyPy, install these dependencies:
These are the requirements for the Debian/Ubuntu based systems. Following are the requirements for RHEL/Rocky/Alma/CentOS:
Now that we have these requirements out of the way, there is another requirement: A completely up-to-date GCC. This is a C/C++ Compiler that is used to build some parts of PyPy. I don’t know how much of PyPy is built using the Compiler, whether it is mostly the whole thing, or only a little bit, but the most up to date gcc is what we are seeking, and at the time of this writing that is GCC 14.
I will be typing out the instructions to compile GCC 14. If you don’t want to build GCC 14 and want to instead use the default, built-in GCC to compile PyPy, then ignore what is below:
As for starting the PyPy build, you also need a version of PyPy to build PyPy with. This can be confusing, but it’s true, you need python or pypy to build pypy. You can use an old version of Python 2, or as I would recommend use the following command to download PyPy:
This will install PyPy 2.7 (Python 2.7) and now we are ready to build our first PyPy.
This begins with opening a console into the root of the source you downloaded from that link that is on my website, and then entering the following command into your terminal:
this will begin the build. The alternative method is to enter this command into your console:
Where it says, “your-path-to” meaning, your path to the next folder, which is called pypy2.7-v7.3.13, so fill in the path that will take you to the -src root. This is kind of extra work, because you can just open a terminal at the root of the source, or you may already have that terminal open. If you’re already at the root of the source, your command will look like this: ./pypy2.7-v7.3.13-src/rpython…
Notice the dot at the beginning of that command. It tells the computer to use the current folder that the terminal is in, and to find the file or folder with the name of, whatever you type in.
At last this starts the build. The build takes about 1 hour, it’s kinda slow because it all runs on 1 thread. So really, this is like a 10 minute build, but because we’re just using 1-thread of our CPU it takes much, much longer. For instance, on my machine GCC build uses 16-threads.
Assuming we are at the root source folder:
This typically works because we are in the root folder already, so what this does isn’t entirely clear, the author didn’t leave much notes, but I do know that CFFI stands for something like converting Python code into C, it’s a library for converting anyway, run the command, you shouldn’t get any errors. If you get the error about “openssl” or something, it’s because your using a version of python you built yourself I think, and that is missing the CFFI extension… I don’t know how to fix this error, and i’ve spent time googling it to try to find a solution but it seems like there’s something you have to do that isn’t being said on any of the websites, because firstly installing python-cffi you have to be on ubuntu 20.04 or it won’t install. Anyway go back to the part of this tutorial where it says to install the snap “pypy –classic” and go from there, alternatively you can continue on without cffi, by running the command again without cffi (I forget what the argument — is)
Lastly we must package PyPy, by running the following command:
As for archive name, since people might be using it, this is also the folder name for the package that is produced. So I keep it all lowercase as someone might be typing in the name of the folder. you can change it to pypy2-your-name-or-company
Okay after running that command, there’s PyPy in your system’s /tmp folder!
the folder is usually called usession-release-pypy2.7-v7.3.13-1 or pypy3.10 for 3.10.
Nextly we add this version of python to your system:
Add this folder to your system’s configuration, I only know how to do it on ubuntu/debian: open /home/madness/.bashrc where madness is your username. This will open the bash configuration file for your system, and you can add PyPy that you just made to your system.
I forgot to mention you must choose where to put pypy, and in the system configuration you must put in the correct path/to/pypy/bin
I guess the most official, proper place to put it would be /opt, so drag the compressed pypy2 file from /tmp and put it into /opt/pypy
As you can see above I keep these things in a ~/Compilers folder, but you don’t have to, you can put it anywhere, you just can’t move it or these things will stop working…
Now we must do one last thing to install PyPy. Open your /bin folder and make a link of the PyPy you compiled. We’re dealing with two /bin folders now: the other one is inside of your pypy folder. So open /opt/pypy/pypy2-your-name/bin and make a link of the pypy executable in that folder, then transfer the link to the /bin folder for your system. This is, right click the pypy executable and click make link or something.
Now open your console, and type pypy2
You have a PyPy version that was built with the latest C++ compiler out there! Next step:
This will remove from your system the snap “pypy” that you used to compile PyPy, you now have your own version of pypy for your system to use. Alternatively, you could make more links, like a link to python2, but you get the idea.
Next we build pypy3, but that is the same, I will leave that to you.
Continuing on, we could re-build pypy2 with our own pypy2, because our pypy2 was built with a pypy2 that was built with like compiler version 10, and we have compiler version 14. Not exactly sure how beneficial this is, but I would guess it would at least have some gain, reason enough to do it anyway.