Python Compiling

Terry Reedy tjreedy at
Fri Sep 20 18:26:51 EDT 2002

"Terje Johan Abrahamsen" <spoermeg at> wrote in message
news:amfveg$5g64k$1 at
> why is not Python a compiled  language?

This has been a subject of much discussion and work.

One answer: portability (see below) and ease of use for humans rather
than computers.

Another possible answer: it is, sort of.  CPython compiles Python code
to Python bytecode (stored in .pyc files).  Jython compiles Python
code to Java bytecode.  In either case, you can run code (raw ascii or
compiled bytecode) that does not use machine-specific features on most
any machine that has a decent C compiler or Java system -- without a
bunch of #ifdefs.

Psyco compiles Python functions (or parts thereof) to special-purpose
machine code.  But it is only available for machines whose machine
code it has been adapted to.

Pyrex adds statements needed to supply the information needed to
translate Python code to C and thence compile with a local C compiler.
There is at least one other system (name escaped me for the moment)
for converting numerical code to C and machine code.

Another answer is that the obvious, straigthforward method of
compiling Python would not gain as much as one would expect, because
of its dynamic name binding.  Much better to identify and rewrite in
C/C++ just the functions that are actual or potential bottlenecks.

Terry J. Reedy

More information about the Python-list mailing list