How to Compile CPython on Debian-Based Linux
This is a short blog post to remind myself how to compile CPython from its source.
You need to get the source files for Python as you need to give the C compiler (and other tools) the needed instructions for producing machine code. The CPython source is available on Github. Using git, you can download with
$ git clone https://github.com/python/cpython.gitYou should install build-essential which provides tooling for building Debian packages. This can be done with apt:
$ sudo apt install build-essentialNext install these assorted packages:
$ sudo apt install libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev liblzma-dev libffi-devHere is a brief description of each package:
Now run the configuration tool that the Python dev’s have kindly prepared. It will prepare a makefile for everything you need to build CPython.
$ ./configure --with-pydebugThe --with-pydebug tells configure to use a debugging hook.
Finally, you can just run make.
$ makeThat’s pretty much it. If you want to silence the large standard output, you can add an -s. By default make will compile the first target specified in the make file, which for this project is actually the entirety of CPython itself. You can specify special build targets related to building, testing, installation, and other topics.