Python compilers?

Fuzzyman michael at foord.net
Fri May 21 06:01:13 EDT 2004


simoninusa2001 at yahoo.co.uk (simo) wrote in message news:<30260531.0405180848.42e2919d at posting.google.com>...
> Leif K-Brooks <eurleif at ecritters.biz> wrote:
> 
> > > Is anyone working on a python-to-native compiler?
> > > I'd be interested in taking a look.
>  

Various people on various projects... most still at the vapourware
stage.
In essence python is a dynamic interpreted language though - in order
to make it suitable for 'compilation' you have to remove some of the
advantages.

Funnily though, most people call Java a compiled language, but it only
compiles to Java bytecode which runs on the virtual machine. Python
precompiles to python bytecode which runs on the python virtual
machine. So arguably it is *as* compiled as Java.....

> > If it's faster code execution, the primary slowdown with a very 
> > high-level language like Python is caused by high-level data structures 
> > (introspection, everything being an object, etc.), not the code itself. 
> > A native compiler would still have to use high-level data structures to 
> > work with all Python code, so the speed increase wouldn't be very much.
> 
> I think the main slowdown most people would see is the startup time -
> the interpreter takes way too long to start (why the company where I
> work won't replace Perl/PHP with Python).
> 

It's not a problem I've been particularly aware of.
Lots of projects to increase execution speed. Psyco is *very* good and
very useable of x86 machines. I use it and see a real speed increase
of approx 10 times on a couple of applications I 've done - anagram
generator and binary interleaving... both of which are processor
intensive. It doesn't address startup speed though.........

> > If it's ease of distribution you're looking for, I think distutils can 
> > make standalone programs on Windows, and most Linux distros have Python 
> > installed by default.
> 
> Oh that one is funny - do most distro's have PyQT and wxPython (and
> their supporting Qt/GKT libs) installed by default, oh and which ones
> come with 2.3 by default?
> 

No - and worse PyQT is commercial only on windoze.
You need py2exe (or similar) to make standalone programs that will run
without python. It's not difficult though.

> > If you just think a compiler would be cool (or would like to see how it 
> > would be done), check out Psyco, Pyrex, and probably some other 
> > projects. Pyrex even combats the speed issue by allowing native C types 
> > to be used in addition to Python high-level types.
> 
> I thought Pyrex was a hybrid of C and Python (like Jython/Java) not
> actually a Python-to-C convertor? And Pysco is just a different VM
> isn't it?
> 

That's right - Pyrex is a new language that mixes python and C syntax.
You can also use it to easily build python extensions.

> I could really push Python where I work if there was a native
> compiler, my company uses C/C++/Java/Qt and were looking at QSA as a
> way to allow the user to script things, but as all of our products
> integrate with our software protection system, we can't be
> distributing source or easily decompiled bytecode!
> 
> We could replace the whole lot with PyQt and use an embedded Python
> interpreter for the scripting! Ah the frustration :-(

if you're lookibng at scripting then you'll be embedding an
interpreter *anyway*.
There *isn't* a native compiler... because python isn't a compiled
language.
*But* bytecode isn't *easily* decompiled (and decompyler is no longer
publicly available) and speed critical stuff/stuff that needs to be
compiled for security reasons can be compiled using Pyrex - which
handles all the interfacing of python to C and you get the best of
both worlds in terms of syntax.

No reason you shouldn't distribute the PyQt libraries *with* your
program - assuming you stick to the relevant licenses.

Regards,


Fuzzy

http://www.voidspace.org.uk/atlantibots/pythonutils.html



More information about the Python-list mailing list