compile python .py file without executing

The py_compile module provides a function to generate a byte-code file from a source file, and another function used when the module source file is invoked as a script.

python -m py_compile fileA.py fileB.py fileC.py

Yes, there is module compileall. Here's an example that compiles all the .py files in a directory (but not sub-directories):

python -m compileall -l myDirectory

In fact if you're on Linux you may already have a /usr/bin/py_compilefiles command in your PATH. It wraps the the py_compile module mentioned by other people. If you're not on Linux, here's the script code.

Tags:

Python