python bytecode questions.

Duncan Booth duncan.booth at invalid.invalid
Tue Oct 9 04:32:05 EDT 2007


warhero <beingthexemplarylists at gmail.com> wrote:

> First question, I can't seem to get any python bytecode to be
> produced. I've tried different techniques from chapter 30.8 to chapter
> 31 of the python guide.. I was under the assumption that after
> compiling a file, it would output a pyc file, but where does it go?
> Any help would be appreciated.

Any time you import a python file it will be compiled (if it hasn't already 
been compiled) and a .pyc file will be generated in the same directory as 
the source file (so long as you can write a file to that directory).

N.B. This only happens when you import a module: when you run a .py file as 
a script it is still compiled, but no .pyc is output. If this worries you 
then write a very short .py file which just imports the main program 
module and calls some startup function.

> 
> Second, Are there any other projects out for bundling python bytecode
> files, making it able to use a couple files to distribute an entire
> app??  I saw one of the effbot site but it's old as it was written for
> 1.4..

For Windows you can make standalone executables with py2exe 
(http://www.py2exe.org/)

More generally, assuming that Python is already installed, the trend seems 
to be for packaging your code as a Python egg 
(http://peak.telecommunity.com/DevCenter/PythonEggs).

> Third, can distributing code in pyc files, speed up the application?
> Or would speed increases only be seen upon application initialization?
> As an example, let's say I'm running an application server, would
> distributing the source in some pyc files with a bootstrapper be any
> faster overall, or just on init??
> 
No, the only gain is that you save the initial compile.



More information about the Python-list mailing list