Compiling Python Compiling Python python python

Compiling Python


python yourfile.py

You have to have python installed first. It will automatically compile your file into a .pyc binary, and then run it for you. It will automatically recompile any time your file changes.

http://www.python.org/download/


Python compiles its files to bytecode before executing them. That means you have to have a Python interpreter installed on the target machine.

If you don't want to install Python on the target machine use py2exe, py2app or something similar.


If you just want to compile sources, without running them, you can do this

compileall.py <directory>

this command will compile python code in that directory recursively

compileall script is usually located in directory like

/usr/local/lib/python2.6

i.e. <prefix>/lib/python2.6 (or similar, depending on prefixes set a python configuration)

As Lulu suggests, you should make sure that resulting .pyc and .pyo files are executable by the users you care about.

compileall can also be used as a module

import compileallcompileall.compile_dir(path)