How to compile a python script to *.pyo
Martin Franklin
MFranklin1 at gatwick.westerngeco.slb.com
Thu Apr 3 14:24:07 EST 2003
danny at iamlearning.com wrote:
> I'm new on this, please bear with we.
>
> Let's say I have this script:
>
> --------------------------
> #!/usr/bin/env python
> x = 'Hello Python'
>
> print x,
>
> --------------------------
>
> How can I compile this script to *.pyo?
I'll ignore the why's and wherefore's and give you what I consider a
straight answer.....
pydoc compileall
Python Library Documentation: module compileall
NAME
compileall - Module/script to "compile" all .py files to .pyc (or
.pyo) file.
FILE
/usr/local/lib/python2.2/compileall.py
DESCRIPTION
When called as a script with arguments, this compiles the directories
given as arguments recursively; the -l option prevents it from
recursing into directories.
Without arguments, if compiles all modules on sys.path, without
recursing into subdirectories. (Even though it should do so for
packages -- for now, you'll have to deal with packages separately.)
See module py_compile for details of the actual byte-compilation.
FUNCTIONS
compile_dir(dir, maxlevels=10, ddir=None, force=0, rx=None)
Byte-compile all modules in the given directory tree.
..... snip .....
I use this for yes you've guessed it compiling my applications, on the fly
as they are installed.
Regards
Martin
More information about the Python-list
mailing list