Building CPython

Chris Angelico rosuav at gmail.com
Thu May 14 12:09:29 EDT 2015


On Fri, May 15, 2015 at 1:51 AM, BartC <bc at freeuk.com> wrote:
> OK, the answer seems to be No then - you can't just trivially compile the C
> modules that comprise the sources with the nearest compiler to hand. So much
> for C's famous portability!
>
> (Actually, I think you already lost me on your first line.)
>
> That's a shame because I wanted to tinker with the main dispatcher loop to
> try and find out what exactly is making it slow. Nothing that seems obvious
> at first sight. (The comments even talk about improving branch prediction on
> certain architectures, even though the performance is a couple of magnitudes
> away from that kind of optimisation being relevant.)

C's portability isn't really sufficient for building a huge project,
so what you generally end up with is a huge slab of common code that
doesn't change from platform to platform, plus a (relatively) tiny
section of platform-specific code, such as makefiles/project files,
linker definitions, and so on. When you start hacking on CPython, you
don't generally have to consider which platform you're aiming at, as
long as you're building on one of the ones that's well supported;
trying to port Python to a new compiler on a known OS is actually
about as much work as porting it to a known compiler on a new OS. (I
know this, because I've attempted both - using mingw on Windows, and
gcc on OS/2. It's a big job either way.)

If you want to just quickly play around with CPython's sources, I
would strongly recommend getting yourself a Linux box. Either spin up
some actual hardware with actual Linux, or grab a virtualization
engine like VMWare, VirtualBox, etc, etc, and installing into a VM.
With a Debian-based Linux (Debian, Ubuntu, Mint, etc), you should
simply be able to:

sudo apt-get build-dep python3

to get all the build dependencies for Python 3; that, plus the source
code, should be enough to get you a'building. Similar simplicities are
available for other Linux distros, but I'll let someone else recommend
them.

Even when you have all the appropriate build tools, Windows can be at
times a pain for building software on. The general philosophy of
Windows is that you should normally be taking ready-made binaries; the
general philosophy of Linux is that it's perfectly normal to spin up
your own binaries from the distributed source code. It's not
impossible to build on Windows, by any means, but be prepared for
extra hassles and less support from the OS than you might like.

ChrisA



More information about the Python-list mailing list