compileall — Byte-compile Python libraries¶This module provides some utility functions to support installing Python libraries. These functions compile Python source files in a directory tree, allowing users without permission to write to the libraries to take advantage of cached byte-code files. This module may also be used as a script (using the -m Python flag) to compile Python sources. Directories to recursively traverse (passing -l stops the recursive behavior) for sources are listed on the command line. If no arguments are given, the invocation is equivalent to -l sys.path. Printing lists of the files compiled can be disabled with the -q flag. In addition, the -x option takes a regular expression argument. All files that match the expression will be skipped.
To force a recompile of all the .py files in the Lib/ subdirectory and all its subdirectories: import compileall
compileall.compile_dir('Lib/', force=True)
# Perform same compilation, excluding files in .svn directories.
import re
compileall.compile_dir('Lib/', rx=re.compile('/[.]svn'), force=True)
See also
|