3.25 py_compile -- Compile Python source files

The py_compile module provides a single function to generate a byte-code file from a source file.

Though not often needed, this function can be useful when installing modules for shared use, especially if some of the users may not have permission to write the byte-code cache files in the directory containing the source code.

compile (file[, cfile[, dfile]])
Compile a source file to byte-code and write out the byte-code cache file. The source code is loaded from the file name file. The byte-code is written to cfile, which defaults to file + 'c' ('o' if optimization is enabled in the current interpreter). If dfile is specified, it is used as the name of the source file in error messages instead of file.

See Also:

Module compileall:
Utilities to compile all Python source files in a directory tree.


Send comments on this document to python-docs@python.org.