Re: need to generate .pyc files

Guido.van.Rossum@cwi.nl
Tue, 03 May 1994 13:14:43 +0200

> I really like the "import generates .pyc when necessary" feature
> for development as it optimizes performance without taking away
> the usefulness (to developers) of interpreted code. For
> distribution of complete systems, however, it would be handy to
> be able to generate the .pyc from a make file (i.e., without
> actually executing code which may cause side effects, etc). Is
> this possible in python?

Check out the 'importall' module. It is written for this purpose.
You may have to adapt it to check a particular directory instead
everythong on sys.path. It assumes that importing a module isn't that
drastic (in particular that the module doesn't start its main()
program right away -- this should only done if __name__ == '__main__').

> Further, I wonder if it is possible to generate a "compiled"
> version of python scripts.

That's not necessary -- .pyc files ARE compiled versions. (If I
understand your question correctly.)

If you mean to generate a stand-alone binary, the "freeze" script
(Demo/scripts/freeze.py) is supposed to do that. It is broken in the
1.0.1 distribution but Jaap Vermeulen gave me a fixed version which
will be distributed in 1.0.2.

--Guido van Rossum, CWI, Amsterdam <Guido.van.Rossum@cwi.nl>
URL: <http://www.cwi.nl/cwi/people/Guido.van.Rossum.html>