gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

685 line
54KB

  1. <!DOCTYPE html>
  2. <html lang="en" data-content_root="../">
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
  6. <meta property="og:title" content="compileall — Byte-compile Python libraries" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/compileall.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/compileall.py This module provides some utility functions to support installing Python libraries. These functions compile Python source files in a directory tree. This module can b..." />
  11. <meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
  12. <meta property="og:image:alt" content="Python documentation" />
  13. <meta name="description" content="Source code: Lib/compileall.py This module provides some utility functions to support installing Python libraries. These functions compile Python source files in a directory tree. This module can b..." />
  14. <meta property="og:image:width" content="200" />
  15. <meta property="og:image:height" content="200" />
  16. <meta name="theme-color" content="#3776ab" />
  17. <title>compileall — Byte-compile Python libraries &#8212; Python 3.12.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
  18. <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=80d5e7a1" />
  19. <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=bb723527" />
  20. <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=b20cc3f5" />
  21. <script src="../_static/documentation_options.js?v=2c828074"></script>
  22. <script src="../_static/doctools.js?v=888ff710"></script>
  23. <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
  24. <script src="../_static/sidebar.js"></script>
  25. <link rel="search" type="application/opensearchdescription+xml"
  26. title="Search within Python 3.12.3 documentation"
  27. href="../_static/opensearch.xml"/>
  28. <link rel="author" title="About these documents" href="../about.html" />
  29. <link rel="index" title="Index" href="../genindex.html" />
  30. <link rel="search" title="Search" href="../search.html" />
  31. <link rel="copyright" title="Copyright" href="../copyright.html" />
  32. <link rel="next" title="dis — Disassembler for Python bytecode" href="dis.html" />
  33. <link rel="prev" title="py_compile — Compile Python source files" href="py_compile.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/compileall.html" />
  35. <style>
  36. @media only screen {
  37. table.full-width-table {
  38. width: 100%;
  39. }
  40. }
  41. </style>
  42. <link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
  43. <link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
  44. <script type="text/javascript" src="../_static/copybutton.js"></script>
  45. <script type="text/javascript" src="../_static/menu.js"></script>
  46. <script type="text/javascript" src="../_static/search-focus.js"></script>
  47. <script type="text/javascript" src="../_static/themetoggle.js"></script>
  48. </head>
  49. <body>
  50. <div class="mobile-nav">
  51. <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
  52. aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
  53. <nav class="nav-content" role="navigation">
  54. <label for="menuToggler" class="toggler__label">
  55. <span></span>
  56. </label>
  57. <span class="nav-items-wrapper">
  58. <a href="https://www.python.org/" class="nav-logo">
  59. <img src="../_static/py.svg" alt="Python logo"/>
  60. </a>
  61. <span class="version_switcher_placeholder"></span>
  62. <form role="search" class="search" action="../search.html" method="get">
  63. <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
  64. <path fill-rule="nonzero" fill="currentColor" d="M15.5 14h-.79l-.28-.27a6.5 6.5 0 001.48-5.34c-.47-2.78-2.79-5-5.59-5.34a6.505 6.505 0 00-7.27 7.27c.34 2.8 2.56 5.12 5.34 5.59a6.5 6.5 0 005.34-1.48l.27.28v.79l4.25 4.25c.41.41 1.08.41 1.49 0 .41-.41.41-1.08 0-1.49L15.5 14zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
  65. </svg>
  66. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
  67. <input type="submit" value="Go"/>
  68. </form>
  69. </span>
  70. </nav>
  71. <div class="menu-wrapper">
  72. <nav class="menu" role="navigation" aria-label="main navigation">
  73. <div class="language_switcher_placeholder"></div>
  74. <label class="theme-selector-label">
  75. Theme
  76. <select class="theme-selector" oninput="activateTheme(this.value)">
  77. <option value="auto" selected>Auto</option>
  78. <option value="light">Light</option>
  79. <option value="dark">Dark</option>
  80. </select>
  81. </label>
  82. <div>
  83. <h3><a href="../contents.html">Table of Contents</a></h3>
  84. <ul>
  85. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a><ul>
  86. <li><a class="reference internal" href="#command-line-use">Command-line use</a></li>
  87. <li><a class="reference internal" href="#public-functions">Public functions</a></li>
  88. </ul>
  89. </li>
  90. </ul>
  91. </div>
  92. <div>
  93. <h4>Previous topic</h4>
  94. <p class="topless"><a href="py_compile.html"
  95. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — Compile Python source files</a></p>
  96. </div>
  97. <div>
  98. <h4>Next topic</h4>
  99. <p class="topless"><a href="dis.html"
  100. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> — Disassembler for Python bytecode</a></p>
  101. </div>
  102. <div role="note" aria-label="source link">
  103. <h3>This Page</h3>
  104. <ul class="this-page-menu">
  105. <li><a href="../bugs.html">Report a Bug</a></li>
  106. <li>
  107. <a href="https://github.com/python/cpython/blob/main/Doc/library/compileall.rst"
  108. rel="nofollow">Show Source
  109. </a>
  110. </li>
  111. </ul>
  112. </div>
  113. </nav>
  114. </div>
  115. </div>
  116. <div class="related" role="navigation" aria-label="related navigation">
  117. <h3>Navigation</h3>
  118. <ul>
  119. <li class="right" style="margin-right: 10px">
  120. <a href="../genindex.html" title="General Index"
  121. accesskey="I">index</a></li>
  122. <li class="right" >
  123. <a href="../py-modindex.html" title="Python Module Index"
  124. >modules</a> |</li>
  125. <li class="right" >
  126. <a href="dis.html" title="dis — Disassembler for Python bytecode"
  127. accesskey="N">next</a> |</li>
  128. <li class="right" >
  129. <a href="py_compile.html" title="py_compile — Compile Python source files"
  130. accesskey="P">previous</a> |</li>
  131. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  132. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  133. <li class="switchers">
  134. <div class="language_switcher_placeholder"></div>
  135. <div class="version_switcher_placeholder"></div>
  136. </li>
  137. <li>
  138. </li>
  139. <li id="cpython-language-and-version">
  140. <a href="../index.html">3.12.3 Documentation</a> &#187;
  141. </li>
  142. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  143. <li class="nav-item nav-item-2"><a href="language.html" accesskey="U">Python Language Services</a> &#187;</li>
  144. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a></li>
  145. <li class="right">
  146. <div class="inline-search" role="search">
  147. <form class="inline-search" action="../search.html" method="get">
  148. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  149. <input type="submit" value="Go" />
  150. </form>
  151. </div>
  152. |
  153. </li>
  154. <li class="right">
  155. <label class="theme-selector-label">
  156. Theme
  157. <select class="theme-selector" oninput="activateTheme(this.value)">
  158. <option value="auto" selected>Auto</option>
  159. <option value="light">Light</option>
  160. <option value="dark">Dark</option>
  161. </select>
  162. </label> |</li>
  163. </ul>
  164. </div>
  165. <div class="document">
  166. <div class="documentwrapper">
  167. <div class="bodywrapper">
  168. <div class="body" role="main">
  169. <section id="module-compileall">
  170. <span id="compileall-byte-compile-python-libraries"></span><h1><a class="reference internal" href="#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code></a> — Byte-compile Python libraries<a class="headerlink" href="#module-compileall" title="Link to this heading">¶</a></h1>
  171. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/compileall.py">Lib/compileall.py</a></p>
  172. <hr class="docutils" />
  173. <p>This module provides some utility functions to support installing Python
  174. libraries. These functions compile Python source files in a directory tree.
  175. This module can be used to create the cached byte-code files at library
  176. installation time, which makes them available for use even by users who don’t
  177. have write permission to the library directories.</p>
  178. <div class="availability docutils container">
  179. <p><a class="reference internal" href="intro.html#availability"><span class="std std-ref">Availability</span></a>: not Emscripten, not WASI.</p>
  180. <p>This module does not work or is not available on WebAssembly platforms
  181. <code class="docutils literal notranslate"><span class="pre">wasm32-emscripten</span></code> and <code class="docutils literal notranslate"><span class="pre">wasm32-wasi</span></code>. See
  182. <a class="reference internal" href="intro.html#wasm-availability"><span class="std std-ref">WebAssembly platforms</span></a> for more information.</p>
  183. </div>
  184. <section id="command-line-use">
  185. <span id="compileall-cli"></span><h2>Command-line use<a class="headerlink" href="#command-line-use" title="Link to this heading">¶</a></h2>
  186. <p>This module can work as a script (using <strong class="program">python -m compileall</strong>) to
  187. compile Python sources.</p>
  188. <dl class="std option">
  189. <dt class="sig sig-object std" id="cmdoption-compileall-arg-directory">
  190. <span class="sig-name descname"><span class="pre">directory</span></span><span class="sig-prename descclassname"> <span class="pre">...</span></span><a class="headerlink" href="#cmdoption-compileall-arg-directory" title="Link to this definition">¶</a></dt>
  191. <dt class="sig sig-object std" id="cmdoption-compileall-arg-file">
  192. <span class="sig-name descname"><span class="pre">file</span></span><span class="sig-prename descclassname"> <span class="pre">...</span></span><a class="headerlink" href="#cmdoption-compileall-arg-file" title="Link to this definition">¶</a></dt>
  193. <dd><p>Positional arguments are files to compile or directories that contain
  194. source files, traversed recursively. If no argument is given, behave as if
  195. the command line was <code class="samp docutils literal notranslate"><span class="pre">-l</span> <em><span class="pre">&lt;directories</span> <span class="pre">from</span> <span class="pre">sys.path&gt;</span></em></code>.</p>
  196. </dd></dl>
  197. <dl class="std option">
  198. <dt class="sig sig-object std" id="cmdoption-compileall-l">
  199. <span class="sig-name descname"><span class="pre">-l</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-l" title="Link to this definition">¶</a></dt>
  200. <dd><p>Do not recurse into subdirectories, only compile source code files directly
  201. contained in the named or implied directories.</p>
  202. </dd></dl>
  203. <dl class="std option">
  204. <dt class="sig sig-object std" id="cmdoption-compileall-f">
  205. <span class="sig-name descname"><span class="pre">-f</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-f" title="Link to this definition">¶</a></dt>
  206. <dd><p>Force rebuild even if timestamps are up-to-date.</p>
  207. </dd></dl>
  208. <dl class="std option">
  209. <dt class="sig sig-object std" id="cmdoption-compileall-q">
  210. <span class="sig-name descname"><span class="pre">-q</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-q" title="Link to this definition">¶</a></dt>
  211. <dd><p>Do not print the list of files compiled. If passed once, error messages will
  212. still be printed. If passed twice (<code class="docutils literal notranslate"><span class="pre">-qq</span></code>), all output is suppressed.</p>
  213. </dd></dl>
  214. <dl class="std option">
  215. <dt class="sig sig-object std" id="cmdoption-compileall-d">
  216. <span class="sig-name descname"><span class="pre">-d</span></span><span class="sig-prename descclassname"> <span class="pre">destdir</span></span><a class="headerlink" href="#cmdoption-compileall-d" title="Link to this definition">¶</a></dt>
  217. <dd><p>Directory prepended to the path to each file being compiled. This will
  218. appear in compilation time tracebacks, and is also compiled in to the
  219. byte-code file, where it will be used in tracebacks and other messages in
  220. cases where the source file does not exist at the time the byte-code file is
  221. executed.</p>
  222. </dd></dl>
  223. <dl class="std option">
  224. <dt class="sig sig-object std" id="cmdoption-compileall-s">
  225. <span class="sig-name descname"><span class="pre">-s</span></span><span class="sig-prename descclassname"> <span class="pre">strip_prefix</span></span><a class="headerlink" href="#cmdoption-compileall-s" title="Link to this definition">¶</a></dt>
  226. <dd></dd></dl>
  227. <dl class="std option">
  228. <dt class="sig sig-object std" id="cmdoption-compileall-p">
  229. <span class="sig-name descname"><span class="pre">-p</span></span><span class="sig-prename descclassname"> <span class="pre">prepend_prefix</span></span><a class="headerlink" href="#cmdoption-compileall-p" title="Link to this definition">¶</a></dt>
  230. <dd><p>Remove (<code class="docutils literal notranslate"><span class="pre">-s</span></code>) or append (<code class="docutils literal notranslate"><span class="pre">-p</span></code>) the given prefix of paths
  231. recorded in the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files.
  232. Cannot be combined with <code class="docutils literal notranslate"><span class="pre">-d</span></code>.</p>
  233. </dd></dl>
  234. <dl class="std option">
  235. <dt class="sig sig-object std" id="cmdoption-compileall-x">
  236. <span class="sig-name descname"><span class="pre">-x</span></span><span class="sig-prename descclassname"> <span class="pre">regex</span></span><a class="headerlink" href="#cmdoption-compileall-x" title="Link to this definition">¶</a></dt>
  237. <dd><p>regex is used to search the full path to each file considered for
  238. compilation, and if the regex produces a match, the file is skipped.</p>
  239. </dd></dl>
  240. <dl class="std option">
  241. <dt class="sig sig-object std" id="cmdoption-compileall-i">
  242. <span class="sig-name descname"><span class="pre">-i</span></span><span class="sig-prename descclassname"> <span class="pre">list</span></span><a class="headerlink" href="#cmdoption-compileall-i" title="Link to this definition">¶</a></dt>
  243. <dd><p>Read the file <code class="docutils literal notranslate"><span class="pre">list</span></code> and add each line that it contains to the list of
  244. files and directories to compile. If <code class="docutils literal notranslate"><span class="pre">list</span></code> is <code class="docutils literal notranslate"><span class="pre">-</span></code>, read lines from
  245. <code class="docutils literal notranslate"><span class="pre">stdin</span></code>.</p>
  246. </dd></dl>
  247. <dl class="std option">
  248. <dt class="sig sig-object std" id="cmdoption-compileall-b">
  249. <span class="sig-name descname"><span class="pre">-b</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-b" title="Link to this definition">¶</a></dt>
  250. <dd><p>Write the byte-code files to their legacy locations and names, which may
  251. overwrite byte-code files created by another version of Python. The default
  252. is to write files to their <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a> locations and names, which allows
  253. byte-code files from multiple versions of Python to coexist.</p>
  254. </dd></dl>
  255. <dl class="std option">
  256. <dt class="sig sig-object std" id="cmdoption-compileall-r">
  257. <span class="sig-name descname"><span class="pre">-r</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-r" title="Link to this definition">¶</a></dt>
  258. <dd><p>Control the maximum recursion level for subdirectories.
  259. If this is given, then <code class="docutils literal notranslate"><span class="pre">-l</span></code> option will not be taken into account.
  260. <strong class="program">python -m compileall &lt;directory&gt; -r 0</strong> is equivalent to
  261. <strong class="program">python -m compileall &lt;directory&gt; -l</strong>.</p>
  262. </dd></dl>
  263. <dl class="std option">
  264. <dt class="sig sig-object std" id="cmdoption-compileall-j">
  265. <span class="sig-name descname"><span class="pre">-j</span></span><span class="sig-prename descclassname"> <span class="pre">N</span></span><a class="headerlink" href="#cmdoption-compileall-j" title="Link to this definition">¶</a></dt>
  266. <dd><p>Use <em>N</em> workers to compile the files within the given directory.
  267. If <code class="docutils literal notranslate"><span class="pre">0</span></code> is used, then the result of <a class="reference internal" href="os.html#os.cpu_count" title="os.cpu_count"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.cpu_count()</span></code></a>
  268. will be used.</p>
  269. </dd></dl>
  270. <dl class="std option">
  271. <dt class="sig sig-object std" id="cmdoption-compileall-invalidation-mode">
  272. <span class="sig-name descname"><span class="pre">--invalidation-mode</span></span><span class="sig-prename descclassname"> <span class="pre">[timestamp|checked-hash|unchecked-hash]</span></span><a class="headerlink" href="#cmdoption-compileall-invalidation-mode" title="Link to this definition">¶</a></dt>
  273. <dd><p>Control how the generated byte-code files are invalidated at runtime.
  274. The <code class="docutils literal notranslate"><span class="pre">timestamp</span></code> value, means that <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with the source timestamp
  275. and size embedded will be generated. The <code class="docutils literal notranslate"><span class="pre">checked-hash</span></code> and
  276. <code class="docutils literal notranslate"><span class="pre">unchecked-hash</span></code> values cause hash-based pycs to be generated. Hash-based
  277. pycs embed a hash of the source file contents rather than a timestamp. See
  278. <a class="reference internal" href="../reference/import.html#pyc-invalidation"><span class="std std-ref">Cached bytecode invalidation</span></a> for more information on how Python validates
  279. bytecode cache files at runtime.
  280. The default is <code class="docutils literal notranslate"><span class="pre">timestamp</span></code> if the <span class="target" id="index-1"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code> environment
  281. variable is not set, and <code class="docutils literal notranslate"><span class="pre">checked-hash</span></code> if the <code class="docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code>
  282. environment variable is set.</p>
  283. </dd></dl>
  284. <dl class="std option">
  285. <dt class="sig sig-object std" id="cmdoption-compileall-o">
  286. <span class="sig-name descname"><span class="pre">-o</span></span><span class="sig-prename descclassname"> <span class="pre">level</span></span><a class="headerlink" href="#cmdoption-compileall-o" title="Link to this definition">¶</a></dt>
  287. <dd><p>Compile with the given optimization level. May be used multiple times
  288. to compile for multiple levels at a time (for example,
  289. <code class="docutils literal notranslate"><span class="pre">compileall</span> <span class="pre">-o</span> <span class="pre">1</span> <span class="pre">-o</span> <span class="pre">2</span></code>).</p>
  290. </dd></dl>
  291. <dl class="std option">
  292. <dt class="sig sig-object std" id="cmdoption-compileall-e">
  293. <span class="sig-name descname"><span class="pre">-e</span></span><span class="sig-prename descclassname"> <span class="pre">dir</span></span><a class="headerlink" href="#cmdoption-compileall-e" title="Link to this definition">¶</a></dt>
  294. <dd><p>Ignore symlinks pointing outside the given directory.</p>
  295. </dd></dl>
  296. <dl class="std option">
  297. <dt class="sig sig-object std" id="cmdoption-compileall-hardlink-dupes">
  298. <span class="sig-name descname"><span class="pre">--hardlink-dupes</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-compileall-hardlink-dupes" title="Link to this definition">¶</a></dt>
  299. <dd><p>If two <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with different optimization level have
  300. the same content, use hard links to consolidate duplicate files.</p>
  301. </dd></dl>
  302. <div class="versionchanged">
  303. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <code class="docutils literal notranslate"><span class="pre">-i</span></code>, <code class="docutils literal notranslate"><span class="pre">-b</span></code> and <code class="docutils literal notranslate"><span class="pre">-h</span></code> options.</p>
  304. </div>
  305. <div class="versionchanged">
  306. <p><span class="versionmodified changed">Changed in version 3.5: </span>Added the <code class="docutils literal notranslate"><span class="pre">-j</span></code>, <code class="docutils literal notranslate"><span class="pre">-r</span></code>, and <code class="docutils literal notranslate"><span class="pre">-qq</span></code> options. <code class="docutils literal notranslate"><span class="pre">-q</span></code> option
  307. was changed to a multilevel value. <code class="docutils literal notranslate"><span class="pre">-b</span></code> will always produce a
  308. byte-code file ending in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>, never <code class="docutils literal notranslate"><span class="pre">.pyo</span></code>.</p>
  309. </div>
  310. <div class="versionchanged">
  311. <p><span class="versionmodified changed">Changed in version 3.7: </span>Added the <code class="docutils literal notranslate"><span class="pre">--invalidation-mode</span></code> option.</p>
  312. </div>
  313. <div class="versionchanged">
  314. <p><span class="versionmodified changed">Changed in version 3.9: </span>Added the <code class="docutils literal notranslate"><span class="pre">-s</span></code>, <code class="docutils literal notranslate"><span class="pre">-p</span></code>, <code class="docutils literal notranslate"><span class="pre">-e</span></code> and <code class="docutils literal notranslate"><span class="pre">--hardlink-dupes</span></code> options.
  315. Raised the default recursion limit from 10 to
  316. <a class="reference internal" href="sys.html#sys.getrecursionlimit" title="sys.getrecursionlimit"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></a>.
  317. Added the possibility to specify the <code class="docutils literal notranslate"><span class="pre">-o</span></code> option multiple times.</p>
  318. </div>
  319. <p>There is no command-line option to control the optimization level used by the
  320. <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function, because the Python interpreter itself already
  321. provides the option: <strong class="program">python -O -m compileall</strong>.</p>
  322. <p>Similarly, the <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function respects the <a class="reference internal" href="sys.html#sys.pycache_prefix" title="sys.pycache_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.pycache_prefix</span></code></a>
  323. setting. The generated bytecode cache will only be useful if <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> is
  324. run with the same <a class="reference internal" href="sys.html#sys.pycache_prefix" title="sys.pycache_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.pycache_prefix</span></code></a> (if any) that will be used at
  325. runtime.</p>
  326. </section>
  327. <section id="public-functions">
  328. <h2>Public functions<a class="headerlink" href="#public-functions" title="Link to this heading">¶</a></h2>
  329. <dl class="py function">
  330. <dt class="sig sig-object py" id="compileall.compile_dir">
  331. <span class="sig-prename descclassname"><span class="pre">compileall.</span></span><span class="sig-name descname"><span class="pre">compile_dir</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">dir</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxlevels</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">sys.getrecursionlimit()</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ddir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quiet</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">legacy</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">optimize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">workers</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">invalidation_mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stripdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prependdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limit_sl_dest</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hardlink_dupes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#compileall.compile_dir" title="Link to this definition">¶</a></dt>
  332. <dd><p>Recursively descend the directory tree named by <em>dir</em>, compiling all <code class="file docutils literal notranslate"><span class="pre">.py</span></code>
  333. files along the way. Return a true value if all the files compiled successfully,
  334. and a false value otherwise.</p>
  335. <p>The <em>maxlevels</em> parameter is used to limit the depth of the recursion; it
  336. defaults to <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code>.</p>
  337. <p>If <em>ddir</em> is given, it is prepended to the path to each file being compiled
  338. for use in compilation time tracebacks, and is also compiled in to the
  339. byte-code file, where it will be used in tracebacks and other messages in
  340. cases where the source file does not exist at the time the byte-code file is
  341. executed.</p>
  342. <p>If <em>force</em> is true, modules are re-compiled even if the timestamps are up to
  343. date.</p>
  344. <p>If <em>rx</em> is given, its <code class="docutils literal notranslate"><span class="pre">search</span></code> method is called on the complete path to each
  345. file considered for compilation, and if it returns a true value, the file
  346. is skipped. This can be used to exclude files matching a regular expression,
  347. given as a <a class="reference internal" href="re.html#re-objects"><span class="std std-ref">re.Pattern</span></a> object.</p>
  348. <p>If <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> (the default), the filenames and other
  349. information are printed to standard out. Set to <code class="docutils literal notranslate"><span class="pre">1</span></code>, only errors are
  350. printed. Set to <code class="docutils literal notranslate"><span class="pre">2</span></code>, all output is suppressed.</p>
  351. <p>If <em>legacy</em> is true, byte-code files are written to their legacy locations
  352. and names, which may overwrite byte-code files created by another version of
  353. Python. The default is to write files to their <span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a> locations and
  354. names, which allows byte-code files from multiple versions of Python to
  355. coexist.</p>
  356. <p><em>optimize</em> specifies the optimization level for the compiler. It is passed to
  357. the built-in <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function. Accepts also a sequence of optimization
  358. levels which lead to multiple compilations of one <code class="file docutils literal notranslate"><span class="pre">.py</span></code> file in one call.</p>
  359. <p>The argument <em>workers</em> specifies how many workers are used to
  360. compile files in parallel. The default is to not use multiple workers.
  361. If the platform can’t use multiple workers and <em>workers</em> argument is given,
  362. then sequential compilation will be used as a fallback. If <em>workers</em>
  363. is 0, the number of cores in the system is used. If <em>workers</em> is
  364. lower than <code class="docutils literal notranslate"><span class="pre">0</span></code>, a <a class="reference internal" href="exceptions.html#ValueError" title="ValueError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">ValueError</span></code></a> will be raised.</p>
  365. <p><em>invalidation_mode</em> should be a member of the
  366. <a class="reference internal" href="py_compile.html#py_compile.PycInvalidationMode" title="py_compile.PycInvalidationMode"><code class="xref py py-class docutils literal notranslate"><span class="pre">py_compile.PycInvalidationMode</span></code></a> enum and controls how the generated
  367. pycs are invalidated at runtime.</p>
  368. <p>The <em>stripdir</em>, <em>prependdir</em> and <em>limit_sl_dest</em> arguments correspond to
  369. the <code class="docutils literal notranslate"><span class="pre">-s</span></code>, <code class="docutils literal notranslate"><span class="pre">-p</span></code> and <code class="docutils literal notranslate"><span class="pre">-e</span></code> options described above.
  370. They may be specified as <code class="docutils literal notranslate"><span class="pre">str</span></code> or <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>.</p>
  371. <p>If <em>hardlink_dupes</em> is true and two <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with different optimization
  372. level have the same content, use hard links to consolidate duplicate files.</p>
  373. <div class="versionchanged">
  374. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <em>legacy</em> and <em>optimize</em> parameter.</p>
  375. </div>
  376. <div class="versionchanged">
  377. <p><span class="versionmodified changed">Changed in version 3.5: </span>Added the <em>workers</em> parameter.</p>
  378. </div>
  379. <div class="versionchanged">
  380. <p><span class="versionmodified changed">Changed in version 3.5: </span><em>quiet</em> parameter was changed to a multilevel value.</p>
  381. </div>
  382. <div class="versionchanged">
  383. <p><span class="versionmodified changed">Changed in version 3.5: </span>The <em>legacy</em> parameter only writes out <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, not <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files
  384. no matter what the value of <em>optimize</em> is.</p>
  385. </div>
  386. <div class="versionchanged">
  387. <p><span class="versionmodified changed">Changed in version 3.6: </span>Accepts a <a class="reference internal" href="../glossary.html#term-path-like-object"><span class="xref std std-term">path-like object</span></a>.</p>
  388. </div>
  389. <div class="versionchanged">
  390. <p><span class="versionmodified changed">Changed in version 3.7: </span>The <em>invalidation_mode</em> parameter was added.</p>
  391. </div>
  392. <div class="versionchanged">
  393. <p><span class="versionmodified changed">Changed in version 3.7.2: </span>The <em>invalidation_mode</em> parameter’s default value is updated to None.</p>
  394. </div>
  395. <div class="versionchanged">
  396. <p><span class="versionmodified changed">Changed in version 3.8: </span>Setting <em>workers</em> to 0 now chooses the optimal number of cores.</p>
  397. </div>
  398. <div class="versionchanged">
  399. <p><span class="versionmodified changed">Changed in version 3.9: </span>Added <em>stripdir</em>, <em>prependdir</em>, <em>limit_sl_dest</em> and <em>hardlink_dupes</em> arguments.
  400. Default value of <em>maxlevels</em> was changed from <code class="docutils literal notranslate"><span class="pre">10</span></code> to <code class="docutils literal notranslate"><span class="pre">sys.getrecursionlimit()</span></code></p>
  401. </div>
  402. </dd></dl>
  403. <dl class="py function">
  404. <dt class="sig sig-object py" id="compileall.compile_file">
  405. <span class="sig-prename descclassname"><span class="pre">compileall.</span></span><span class="sig-name descname"><span class="pre">compile_file</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">fullname</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">ddir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">rx</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quiet</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">legacy</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">optimize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">invalidation_mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="o"><span class="pre">*</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">stripdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">prependdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">limit_sl_dest</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">hardlink_dupes</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#compileall.compile_file" title="Link to this definition">¶</a></dt>
  406. <dd><p>Compile the file with path <em>fullname</em>. Return a true value if the file
  407. compiled successfully, and a false value otherwise.</p>
  408. <p>If <em>ddir</em> is given, it is prepended to the path to the file being compiled
  409. for use in compilation time tracebacks, and is also compiled in to the
  410. byte-code file, where it will be used in tracebacks and other messages in
  411. cases where the source file does not exist at the time the byte-code file is
  412. executed.</p>
  413. <p>If <em>rx</em> is given, its <code class="docutils literal notranslate"><span class="pre">search</span></code> method is passed the full path name to the
  414. file being compiled, and if it returns a true value, the file is not
  415. compiled and <code class="docutils literal notranslate"><span class="pre">True</span></code> is returned. This can be used to exclude files matching
  416. a regular expression, given as a <a class="reference internal" href="re.html#re-objects"><span class="std std-ref">re.Pattern</span></a> object.</p>
  417. <p>If <em>quiet</em> is <code class="docutils literal notranslate"><span class="pre">False</span></code> or <code class="docutils literal notranslate"><span class="pre">0</span></code> (the default), the filenames and other
  418. information are printed to standard out. Set to <code class="docutils literal notranslate"><span class="pre">1</span></code>, only errors are
  419. printed. Set to <code class="docutils literal notranslate"><span class="pre">2</span></code>, all output is suppressed.</p>
  420. <p>If <em>legacy</em> is true, byte-code files are written to their legacy locations
  421. and names, which may overwrite byte-code files created by another version of
  422. Python. The default is to write files to their <span class="target" id="index-3"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a> locations and
  423. names, which allows byte-code files from multiple versions of Python to
  424. coexist.</p>
  425. <p><em>optimize</em> specifies the optimization level for the compiler. It is passed to
  426. the built-in <a class="reference internal" href="functions.html#compile" title="compile"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code></a> function. Accepts also a sequence of optimization
  427. levels which lead to multiple compilations of one <code class="file docutils literal notranslate"><span class="pre">.py</span></code> file in one call.</p>
  428. <p><em>invalidation_mode</em> should be a member of the
  429. <a class="reference internal" href="py_compile.html#py_compile.PycInvalidationMode" title="py_compile.PycInvalidationMode"><code class="xref py py-class docutils literal notranslate"><span class="pre">py_compile.PycInvalidationMode</span></code></a> enum and controls how the generated
  430. pycs are invalidated at runtime.</p>
  431. <p>The <em>stripdir</em>, <em>prependdir</em> and <em>limit_sl_dest</em> arguments correspond to
  432. the <code class="docutils literal notranslate"><span class="pre">-s</span></code>, <code class="docutils literal notranslate"><span class="pre">-p</span></code> and <code class="docutils literal notranslate"><span class="pre">-e</span></code> options described above.
  433. They may be specified as <code class="docutils literal notranslate"><span class="pre">str</span></code> or <a class="reference internal" href="os.html#os.PathLike" title="os.PathLike"><code class="xref py py-class docutils literal notranslate"><span class="pre">os.PathLike</span></code></a>.</p>
  434. <p>If <em>hardlink_dupes</em> is true and two <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files with different optimization
  435. level have the same content, use hard links to consolidate duplicate files.</p>
  436. <div class="versionadded">
  437. <p><span class="versionmodified added">New in version 3.2.</span></p>
  438. </div>
  439. <div class="versionchanged">
  440. <p><span class="versionmodified changed">Changed in version 3.5: </span><em>quiet</em> parameter was changed to a multilevel value.</p>
  441. </div>
  442. <div class="versionchanged">
  443. <p><span class="versionmodified changed">Changed in version 3.5: </span>The <em>legacy</em> parameter only writes out <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, not <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files
  444. no matter what the value of <em>optimize</em> is.</p>
  445. </div>
  446. <div class="versionchanged">
  447. <p><span class="versionmodified changed">Changed in version 3.7: </span>The <em>invalidation_mode</em> parameter was added.</p>
  448. </div>
  449. <div class="versionchanged">
  450. <p><span class="versionmodified changed">Changed in version 3.7.2: </span>The <em>invalidation_mode</em> parameter’s default value is updated to None.</p>
  451. </div>
  452. <div class="versionchanged">
  453. <p><span class="versionmodified changed">Changed in version 3.9: </span>Added <em>stripdir</em>, <em>prependdir</em>, <em>limit_sl_dest</em> and <em>hardlink_dupes</em> arguments.</p>
  454. </div>
  455. </dd></dl>
  456. <dl class="py function">
  457. <dt class="sig sig-object py" id="compileall.compile_path">
  458. <span class="sig-prename descclassname"><span class="pre">compileall.</span></span><span class="sig-name descname"><span class="pre">compile_path</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">skip_curdir</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">True</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">maxlevels</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">force</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">quiet</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">0</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">legacy</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">False</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">optimize</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">-1</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">invalidation_mode</span></span><span class="o"><span class="pre">=</span></span><span class="default_value"><span class="pre">None</span></span></em><span class="sig-paren">)</span><a class="headerlink" href="#compileall.compile_path" title="Link to this definition">¶</a></dt>
  459. <dd><p>Byte-compile all the <code class="file docutils literal notranslate"><span class="pre">.py</span></code> files found along <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>. Return a
  460. true value if all the files compiled successfully, and a false value otherwise.</p>
  461. <p>If <em>skip_curdir</em> is true (the default), the current directory is not included
  462. in the search. All other parameters are passed to the <a class="reference internal" href="#compileall.compile_dir" title="compileall.compile_dir"><code class="xref py py-func docutils literal notranslate"><span class="pre">compile_dir()</span></code></a>
  463. function. Note that unlike the other compile functions, <code class="docutils literal notranslate"><span class="pre">maxlevels</span></code>
  464. defaults to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  465. <div class="versionchanged">
  466. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added the <em>legacy</em> and <em>optimize</em> parameter.</p>
  467. </div>
  468. <div class="versionchanged">
  469. <p><span class="versionmodified changed">Changed in version 3.5: </span><em>quiet</em> parameter was changed to a multilevel value.</p>
  470. </div>
  471. <div class="versionchanged">
  472. <p><span class="versionmodified changed">Changed in version 3.5: </span>The <em>legacy</em> parameter only writes out <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files, not <code class="docutils literal notranslate"><span class="pre">.pyo</span></code> files
  473. no matter what the value of <em>optimize</em> is.</p>
  474. </div>
  475. <div class="versionchanged">
  476. <p><span class="versionmodified changed">Changed in version 3.7: </span>The <em>invalidation_mode</em> parameter was added.</p>
  477. </div>
  478. <div class="versionchanged">
  479. <p><span class="versionmodified changed">Changed in version 3.7.2: </span>The <em>invalidation_mode</em> parameter’s default value is updated to None.</p>
  480. </div>
  481. </dd></dl>
  482. <p>To force a recompile of all the <code class="file docutils literal notranslate"><span class="pre">.py</span></code> files in the <code class="file docutils literal notranslate"><span class="pre">Lib/</span></code>
  483. subdirectory and all its subdirectories:</p>
  484. <div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">compileall</span>
  485. <span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="s1">&#39;Lib/&#39;</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  486. <span class="c1"># Perform same compilation, excluding files in .svn directories.</span>
  487. <span class="kn">import</span> <span class="nn">re</span>
  488. <span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="s1">&#39;Lib/&#39;</span><span class="p">,</span> <span class="n">rx</span><span class="o">=</span><span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="sa">r</span><span class="s1">&#39;[/</span><span class="se">\\</span><span class="s1">][.]svn&#39;</span><span class="p">),</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  489. <span class="c1"># pathlib.Path objects can also be used.</span>
  490. <span class="kn">import</span> <span class="nn">pathlib</span>
  491. <span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="n">pathlib</span><span class="o">.</span><span class="n">Path</span><span class="p">(</span><span class="s1">&#39;Lib/&#39;</span><span class="p">),</span> <span class="n">force</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>
  492. </pre></div>
  493. </div>
  494. <div class="admonition seealso">
  495. <p class="admonition-title">See also</p>
  496. <dl class="simple">
  497. <dt>Module <a class="reference internal" href="py_compile.html#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code></a></dt><dd><p>Byte-compile a single source file.</p>
  498. </dd>
  499. </dl>
  500. </div>
  501. </section>
  502. </section>
  503. <div class="clearer"></div>
  504. </div>
  505. </div>
  506. </div>
  507. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  508. <div class="sphinxsidebarwrapper">
  509. <div>
  510. <h3><a href="../contents.html">Table of Contents</a></h3>
  511. <ul>
  512. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a><ul>
  513. <li><a class="reference internal" href="#command-line-use">Command-line use</a></li>
  514. <li><a class="reference internal" href="#public-functions">Public functions</a></li>
  515. </ul>
  516. </li>
  517. </ul>
  518. </div>
  519. <div>
  520. <h4>Previous topic</h4>
  521. <p class="topless"><a href="py_compile.html"
  522. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — Compile Python source files</a></p>
  523. </div>
  524. <div>
  525. <h4>Next topic</h4>
  526. <p class="topless"><a href="dis.html"
  527. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">dis</span></code> — Disassembler for Python bytecode</a></p>
  528. </div>
  529. <div role="note" aria-label="source link">
  530. <h3>This Page</h3>
  531. <ul class="this-page-menu">
  532. <li><a href="../bugs.html">Report a Bug</a></li>
  533. <li>
  534. <a href="https://github.com/python/cpython/blob/main/Doc/library/compileall.rst"
  535. rel="nofollow">Show Source
  536. </a>
  537. </li>
  538. </ul>
  539. </div>
  540. </div>
  541. <div id="sidebarbutton" title="Collapse sidebar">
  542. <span>«</span>
  543. </div>
  544. </div>
  545. <div class="clearer"></div>
  546. </div>
  547. <div class="related" role="navigation" aria-label="related navigation">
  548. <h3>Navigation</h3>
  549. <ul>
  550. <li class="right" style="margin-right: 10px">
  551. <a href="../genindex.html" title="General Index"
  552. >index</a></li>
  553. <li class="right" >
  554. <a href="../py-modindex.html" title="Python Module Index"
  555. >modules</a> |</li>
  556. <li class="right" >
  557. <a href="dis.html" title="dis — Disassembler for Python bytecode"
  558. >next</a> |</li>
  559. <li class="right" >
  560. <a href="py_compile.html" title="py_compile — Compile Python source files"
  561. >previous</a> |</li>
  562. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  563. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  564. <li class="switchers">
  565. <div class="language_switcher_placeholder"></div>
  566. <div class="version_switcher_placeholder"></div>
  567. </li>
  568. <li>
  569. </li>
  570. <li id="cpython-language-and-version">
  571. <a href="../index.html">3.12.3 Documentation</a> &#187;
  572. </li>
  573. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  574. <li class="nav-item nav-item-2"><a href="language.html" >Python Language Services</a> &#187;</li>
  575. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a></li>
  576. <li class="right">
  577. <div class="inline-search" role="search">
  578. <form class="inline-search" action="../search.html" method="get">
  579. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  580. <input type="submit" value="Go" />
  581. </form>
  582. </div>
  583. |
  584. </li>
  585. <li class="right">
  586. <label class="theme-selector-label">
  587. Theme
  588. <select class="theme-selector" oninput="activateTheme(this.value)">
  589. <option value="auto" selected>Auto</option>
  590. <option value="light">Light</option>
  591. <option value="dark">Dark</option>
  592. </select>
  593. </label> |</li>
  594. </ul>
  595. </div>
  596. <div class="footer">
  597. &copy;
  598. <a href="../copyright.html">
  599. Copyright
  600. </a>
  601. 2001-2024, Python Software Foundation.
  602. <br />
  603. This page is licensed under the Python Software Foundation License Version 2.
  604. <br />
  605. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  606. <br />
  607. See <a href="/license.html">History and License</a> for more information.<br />
  608. <br />
  609. The Python Software Foundation is a non-profit corporation.
  610. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  611. <br />
  612. <br />
  613. Last updated on Apr 09, 2024 (13:47 UTC).
  614. <a href="/bugs.html">Found a bug</a>?
  615. <br />
  616. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  617. </div>
  618. </body>
  619. </html>
上海开阖软件有限公司 沪ICP备12045867号-1