gooderp18绿色标准版
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

484 行
31KB

  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="py_compile — Compile Python source files" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/library/py_compile.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Source code: Lib/py_compile.py 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 scrip..." />
  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/py_compile.py 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 scrip..." />
  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>py_compile — Compile Python source files &#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="compileall — Byte-compile Python libraries" href="compileall.html" />
  33. <link rel="prev" title="pyclbr — Python module browser support" href="pyclbr.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/library/py_compile.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">py_compile</span></code> — Compile Python source files</a><ul>
  86. <li><a class="reference internal" href="#command-line-interface">Command-Line Interface</a></li>
  87. </ul>
  88. </li>
  89. </ul>
  90. </div>
  91. <div>
  92. <h4>Previous topic</h4>
  93. <p class="topless"><a href="pyclbr.html"
  94. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pyclbr</span></code> — Python module browser support</a></p>
  95. </div>
  96. <div>
  97. <h4>Next topic</h4>
  98. <p class="topless"><a href="compileall.html"
  99. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a></p>
  100. </div>
  101. <div role="note" aria-label="source link">
  102. <h3>This Page</h3>
  103. <ul class="this-page-menu">
  104. <li><a href="../bugs.html">Report a Bug</a></li>
  105. <li>
  106. <a href="https://github.com/python/cpython/blob/main/Doc/library/py_compile.rst"
  107. rel="nofollow">Show Source
  108. </a>
  109. </li>
  110. </ul>
  111. </div>
  112. </nav>
  113. </div>
  114. </div>
  115. <div class="related" role="navigation" aria-label="related navigation">
  116. <h3>Navigation</h3>
  117. <ul>
  118. <li class="right" style="margin-right: 10px">
  119. <a href="../genindex.html" title="General Index"
  120. accesskey="I">index</a></li>
  121. <li class="right" >
  122. <a href="../py-modindex.html" title="Python Module Index"
  123. >modules</a> |</li>
  124. <li class="right" >
  125. <a href="compileall.html" title="compileall — Byte-compile Python libraries"
  126. accesskey="N">next</a> |</li>
  127. <li class="right" >
  128. <a href="pyclbr.html" title="pyclbr — Python module browser support"
  129. accesskey="P">previous</a> |</li>
  130. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  131. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  132. <li class="switchers">
  133. <div class="language_switcher_placeholder"></div>
  134. <div class="version_switcher_placeholder"></div>
  135. </li>
  136. <li>
  137. </li>
  138. <li id="cpython-language-and-version">
  139. <a href="../index.html">3.12.3 Documentation</a> &#187;
  140. </li>
  141. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  142. <li class="nav-item nav-item-2"><a href="language.html" accesskey="U">Python Language Services</a> &#187;</li>
  143. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — Compile Python source files</a></li>
  144. <li class="right">
  145. <div class="inline-search" role="search">
  146. <form class="inline-search" action="../search.html" method="get">
  147. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  148. <input type="submit" value="Go" />
  149. </form>
  150. </div>
  151. |
  152. </li>
  153. <li class="right">
  154. <label class="theme-selector-label">
  155. Theme
  156. <select class="theme-selector" oninput="activateTheme(this.value)">
  157. <option value="auto" selected>Auto</option>
  158. <option value="light">Light</option>
  159. <option value="dark">Dark</option>
  160. </select>
  161. </label> |</li>
  162. </ul>
  163. </div>
  164. <div class="document">
  165. <div class="documentwrapper">
  166. <div class="bodywrapper">
  167. <div class="body" role="main">
  168. <section id="module-py_compile">
  169. <span id="py-compile-compile-python-source-files"></span><h1><a class="reference internal" href="#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> — Compile Python source files<a class="headerlink" href="#module-py_compile" title="Link to this heading">¶</a></h1>
  170. <p><strong>Source code:</strong> <a class="reference external" href="https://github.com/python/cpython/tree/3.12/Lib/py_compile.py">Lib/py_compile.py</a></p>
  171. <hr class="docutils" id="index-0" />
  172. <p>The <a class="reference internal" href="#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> module provides a function to generate a byte-code file
  173. from a source file, and another function used when the module source file is
  174. invoked as a script.</p>
  175. <p>Though not often needed, this function can be useful when installing modules for
  176. shared use, especially if some of the users may not have permission to write the
  177. byte-code cache files in the directory containing the source code.</p>
  178. <dl class="py exception">
  179. <dt class="sig sig-object py" id="py_compile.PyCompileError">
  180. <em class="property"><span class="pre">exception</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">py_compile.</span></span><span class="sig-name descname"><span class="pre">PyCompileError</span></span><a class="headerlink" href="#py_compile.PyCompileError" title="Link to this definition">¶</a></dt>
  181. <dd><p>Exception raised when an error occurs while attempting to compile the file.</p>
  182. </dd></dl>
  183. <dl class="py function">
  184. <dt class="sig sig-object py" id="py_compile.compile">
  185. <span class="sig-prename descclassname"><span class="pre">py_compile.</span></span><span class="sig-name descname"><span class="pre">compile</span></span><span class="sig-paren">(</span><em class="sig-param"><span class="n"><span class="pre">file</span></span></em>, <em class="sig-param"><span class="n"><span class="pre">cfile</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">dfile</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">doraise</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">PycInvalidationMode.TIMESTAMP</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><span class="sig-paren">)</span><a class="headerlink" href="#py_compile.compile" title="Link to this definition">¶</a></dt>
  186. <dd><p>Compile a source file to byte-code and write out the byte-code cache file.
  187. The source code is loaded from the file named <em>file</em>. The byte-code is
  188. written to <em>cfile</em>, which defaults to the <span class="target" id="index-1"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a>/<span class="target" id="index-2"></span><a class="pep reference external" href="https://peps.python.org/pep-0488/"><strong>PEP 488</strong></a> path, ending
  189. in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>.
  190. For example, if <em>file</em> is <code class="docutils literal notranslate"><span class="pre">/foo/bar/baz.py</span></code> <em>cfile</em> will default to
  191. <code class="docutils literal notranslate"><span class="pre">/foo/bar/__pycache__/baz.cpython-32.pyc</span></code> for Python 3.2. If <em>dfile</em> is
  192. specified, it is used instead of <em>file</em> as the name of the source file from
  193. which source lines are obtained for display in exception tracebacks.
  194. If <em>doraise</em> is true, a <a class="reference internal" href="#py_compile.PyCompileError" title="py_compile.PyCompileError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PyCompileError</span></code></a> is raised
  195. when an error is encountered while compiling <em>file</em>. If <em>doraise</em> is false
  196. (the default), an error string is written to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>, but no exception
  197. is raised. This function returns the path to byte-compiled file, i.e.
  198. whatever <em>cfile</em> value was used.</p>
  199. <p>The <em>doraise</em> and <em>quiet</em> arguments determine how errors are handled while
  200. compiling file. If <em>quiet</em> is 0 or 1, and <em>doraise</em> is false, the default
  201. behaviour is enabled: an error string is written to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>, and the
  202. function returns <code class="docutils literal notranslate"><span class="pre">None</span></code> instead of a path. If <em>doraise</em> is true,
  203. a <a class="reference internal" href="#py_compile.PyCompileError" title="py_compile.PyCompileError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">PyCompileError</span></code></a> is raised instead. However if <em>quiet</em> is 2,
  204. no message is written, and <em>doraise</em> has no effect.</p>
  205. <p>If the path that <em>cfile</em> becomes (either explicitly specified or computed)
  206. is a symlink or non-regular file, <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> will be raised.
  207. This is to act as a warning that import will turn those paths into regular
  208. files if it is allowed to write byte-compiled files to those paths. This is
  209. a side-effect of import using file renaming to place the final byte-compiled
  210. file into place to prevent concurrent file writing issues.</p>
  211. <p><em>optimize</em> controls the optimization level and is passed to the built-in
  212. <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. The default of <code class="docutils literal notranslate"><span class="pre">-1</span></code> selects the optimization
  213. level of the current interpreter.</p>
  214. <p><em>invalidation_mode</em> should be a member of the <a class="reference internal" href="#py_compile.PycInvalidationMode" title="py_compile.PycInvalidationMode"><code class="xref py py-class docutils literal notranslate"><span class="pre">PycInvalidationMode</span></code></a>
  215. enum and controls how the generated bytecode cache is invalidated at
  216. runtime. The default is <a class="reference internal" href="#py_compile.PycInvalidationMode.CHECKED_HASH" title="py_compile.PycInvalidationMode.CHECKED_HASH"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PycInvalidationMode.CHECKED_HASH</span></code></a> if
  217. the <span class="target" id="index-3"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code> environment variable is set, otherwise
  218. the default is <a class="reference internal" href="#py_compile.PycInvalidationMode.TIMESTAMP" title="py_compile.PycInvalidationMode.TIMESTAMP"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PycInvalidationMode.TIMESTAMP</span></code></a>.</p>
  219. <div class="versionchanged">
  220. <p><span class="versionmodified changed">Changed in version 3.2: </span>Changed default value of <em>cfile</em> to be <span class="target" id="index-4"></span><a class="pep reference external" href="https://peps.python.org/pep-3147/"><strong>PEP 3147</strong></a>-compliant. Previous
  221. default was <em>file</em> + <code class="docutils literal notranslate"><span class="pre">'c'</span></code> (<code class="docutils literal notranslate"><span class="pre">'o'</span></code> if optimization was enabled).
  222. Also added the <em>optimize</em> parameter.</p>
  223. </div>
  224. <div class="versionchanged">
  225. <p><span class="versionmodified changed">Changed in version 3.4: </span>Changed code to use <a class="reference internal" href="importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a> for the byte-code cache file writing.
  226. This means file creation/writing semantics now match what <a class="reference internal" href="importlib.html#module-importlib" title="importlib: The implementation of the import machinery."><code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code></a>
  227. does, e.g. permissions, write-and-move semantics, etc. Also added the
  228. caveat that <a class="reference internal" href="exceptions.html#FileExistsError" title="FileExistsError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">FileExistsError</span></code></a> is raised if <em>cfile</em> is a symlink or
  229. non-regular file.</p>
  230. </div>
  231. <div class="versionchanged">
  232. <p><span class="versionmodified changed">Changed in version 3.7: </span>The <em>invalidation_mode</em> parameter was added as specified in <span class="target" id="index-5"></span><a class="pep reference external" href="https://peps.python.org/pep-0552/"><strong>PEP 552</strong></a>.
  233. If the <span class="target" id="index-6"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code> environment variable is set,
  234. <em>invalidation_mode</em> will be forced to
  235. <a class="reference internal" href="#py_compile.PycInvalidationMode.CHECKED_HASH" title="py_compile.PycInvalidationMode.CHECKED_HASH"><code class="xref py py-attr docutils literal notranslate"><span class="pre">PycInvalidationMode.CHECKED_HASH</span></code></a>.</p>
  236. </div>
  237. <div class="versionchanged">
  238. <p><span class="versionmodified changed">Changed in version 3.7.2: </span>The <span class="target" id="index-7"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">SOURCE_DATE_EPOCH</span></code> environment variable no longer
  239. overrides the value of the <em>invalidation_mode</em> argument, and determines
  240. its default value instead.</p>
  241. </div>
  242. <div class="versionchanged">
  243. <p><span class="versionmodified changed">Changed in version 3.8: </span>The <em>quiet</em> parameter was added.</p>
  244. </div>
  245. </dd></dl>
  246. <dl class="py class">
  247. <dt class="sig sig-object py" id="py_compile.PycInvalidationMode">
  248. <em class="property"><span class="pre">class</span><span class="w"> </span></em><span class="sig-prename descclassname"><span class="pre">py_compile.</span></span><span class="sig-name descname"><span class="pre">PycInvalidationMode</span></span><a class="headerlink" href="#py_compile.PycInvalidationMode" title="Link to this definition">¶</a></dt>
  249. <dd><p>A enumeration of possible methods the interpreter can use to determine
  250. whether a bytecode file is up to date with a source file. The <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file
  251. indicates the desired invalidation mode in its header. See
  252. <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 invalidates
  253. <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files at runtime.</p>
  254. <div class="versionadded">
  255. <p><span class="versionmodified added">New in version 3.7.</span></p>
  256. </div>
  257. <dl class="py attribute">
  258. <dt class="sig sig-object py" id="py_compile.PycInvalidationMode.TIMESTAMP">
  259. <span class="sig-name descname"><span class="pre">TIMESTAMP</span></span><a class="headerlink" href="#py_compile.PycInvalidationMode.TIMESTAMP" title="Link to this definition">¶</a></dt>
  260. <dd><p>The <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file includes the timestamp and size of the source file,
  261. which Python will compare against the metadata of the source file at
  262. runtime to determine if the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file needs to be regenerated.</p>
  263. </dd></dl>
  264. <dl class="py attribute">
  265. <dt class="sig sig-object py" id="py_compile.PycInvalidationMode.CHECKED_HASH">
  266. <span class="sig-name descname"><span class="pre">CHECKED_HASH</span></span><a class="headerlink" href="#py_compile.PycInvalidationMode.CHECKED_HASH" title="Link to this definition">¶</a></dt>
  267. <dd><p>The <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file includes a hash of the source file content, which Python
  268. will compare against the source at runtime to determine if the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>
  269. file needs to be regenerated.</p>
  270. </dd></dl>
  271. <dl class="py attribute">
  272. <dt class="sig sig-object py" id="py_compile.PycInvalidationMode.UNCHECKED_HASH">
  273. <span class="sig-name descname"><span class="pre">UNCHECKED_HASH</span></span><a class="headerlink" href="#py_compile.PycInvalidationMode.UNCHECKED_HASH" title="Link to this definition">¶</a></dt>
  274. <dd><p>Like <a class="reference internal" href="#py_compile.PycInvalidationMode.CHECKED_HASH" title="py_compile.PycInvalidationMode.CHECKED_HASH"><code class="xref py py-attr docutils literal notranslate"><span class="pre">CHECKED_HASH</span></code></a>, the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file includes a hash of the source
  275. file content. However, Python will at runtime assume the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file is
  276. up to date and not validate the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> against the source file at all.</p>
  277. <p>This option is useful when the <code class="docutils literal notranslate"><span class="pre">.pycs</span></code> are kept up to date by some
  278. system external to Python like a build system.</p>
  279. </dd></dl>
  280. </dd></dl>
  281. <section id="command-line-interface">
  282. <span id="py-compile-cli"></span><h2>Command-Line Interface<a class="headerlink" href="#command-line-interface" title="Link to this heading">¶</a></h2>
  283. <p>This module can be invoked as a script to compile several source
  284. files. The files named in <em>filenames</em> are compiled and the resulting
  285. bytecode is cached in the normal manner. This program does not search
  286. a directory structure to locate source files; it only compiles files
  287. named explicitly. The exit status is nonzero if one of the files could
  288. not be compiled.</p>
  289. <dl class="std option">
  290. <dt class="sig sig-object std" id="cmdoption-python-m-py_compile-arg-file">
  291. <span class="sig-name descname"><span class="pre">&lt;file&gt;</span></span><span class="sig-prename descclassname"> <span class="pre">...</span> <span class="pre">&lt;fileN&gt;</span></span><a class="headerlink" href="#cmdoption-python-m-py_compile-arg-file" title="Link to this definition">¶</a></dt>
  292. <dt class="sig sig-object std" id="cmdoption-python-m-py_compile">
  293. <span class="sig-name descname"><span class="pre">-</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-python-m-py_compile" title="Link to this definition">¶</a></dt>
  294. <dd><p>Positional arguments are files to compile. If <code class="docutils literal notranslate"><span class="pre">-</span></code> is the only
  295. parameter, the list of files is taken from standard input.</p>
  296. </dd></dl>
  297. <dl class="std option">
  298. <dt class="sig sig-object std" id="cmdoption-python-m-py_compile-q">
  299. <span id="cmdoption-python-m-py_compile-quiet"></span><span class="sig-name descname"><span class="pre">-q</span></span><span class="sig-prename descclassname"></span><span class="sig-prename descclassname"><span class="pre">,</span> </span><span class="sig-name descname"><span class="pre">--quiet</span></span><span class="sig-prename descclassname"></span><a class="headerlink" href="#cmdoption-python-m-py_compile-q" title="Link to this definition">¶</a></dt>
  300. <dd><p>Suppress errors output.</p>
  301. </dd></dl>
  302. <div class="versionchanged">
  303. <p><span class="versionmodified changed">Changed in version 3.2: </span>Added support for <code class="docutils literal notranslate"><span class="pre">-</span></code>.</p>
  304. </div>
  305. <div class="versionchanged">
  306. <p><span class="versionmodified changed">Changed in version 3.10: </span>Added support for <a class="reference internal" href="#cmdoption-python-m-py_compile-q"><code class="xref std std-option docutils literal notranslate"><span class="pre">-q</span></code></a>.</p>
  307. </div>
  308. <div class="admonition seealso">
  309. <p class="admonition-title">See also</p>
  310. <dl class="simple">
  311. <dt>Module <a class="reference internal" href="compileall.html#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></dt><dd><p>Utilities to compile all Python source files in a directory tree.</p>
  312. </dd>
  313. </dl>
  314. </div>
  315. </section>
  316. </section>
  317. <div class="clearer"></div>
  318. </div>
  319. </div>
  320. </div>
  321. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  322. <div class="sphinxsidebarwrapper">
  323. <div>
  324. <h3><a href="../contents.html">Table of Contents</a></h3>
  325. <ul>
  326. <li><a class="reference internal" href="#"><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — Compile Python source files</a><ul>
  327. <li><a class="reference internal" href="#command-line-interface">Command-Line Interface</a></li>
  328. </ul>
  329. </li>
  330. </ul>
  331. </div>
  332. <div>
  333. <h4>Previous topic</h4>
  334. <p class="topless"><a href="pyclbr.html"
  335. title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pyclbr</span></code> — Python module browser support</a></p>
  336. </div>
  337. <div>
  338. <h4>Next topic</h4>
  339. <p class="topless"><a href="compileall.html"
  340. title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a></p>
  341. </div>
  342. <div role="note" aria-label="source link">
  343. <h3>This Page</h3>
  344. <ul class="this-page-menu">
  345. <li><a href="../bugs.html">Report a Bug</a></li>
  346. <li>
  347. <a href="https://github.com/python/cpython/blob/main/Doc/library/py_compile.rst"
  348. rel="nofollow">Show Source
  349. </a>
  350. </li>
  351. </ul>
  352. </div>
  353. </div>
  354. <div id="sidebarbutton" title="Collapse sidebar">
  355. <span>«</span>
  356. </div>
  357. </div>
  358. <div class="clearer"></div>
  359. </div>
  360. <div class="related" role="navigation" aria-label="related navigation">
  361. <h3>Navigation</h3>
  362. <ul>
  363. <li class="right" style="margin-right: 10px">
  364. <a href="../genindex.html" title="General Index"
  365. >index</a></li>
  366. <li class="right" >
  367. <a href="../py-modindex.html" title="Python Module Index"
  368. >modules</a> |</li>
  369. <li class="right" >
  370. <a href="compileall.html" title="compileall — Byte-compile Python libraries"
  371. >next</a> |</li>
  372. <li class="right" >
  373. <a href="pyclbr.html" title="pyclbr — Python module browser support"
  374. >previous</a> |</li>
  375. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  376. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  377. <li class="switchers">
  378. <div class="language_switcher_placeholder"></div>
  379. <div class="version_switcher_placeholder"></div>
  380. </li>
  381. <li>
  382. </li>
  383. <li id="cpython-language-and-version">
  384. <a href="../index.html">3.12.3 Documentation</a> &#187;
  385. </li>
  386. <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> &#187;</li>
  387. <li class="nav-item nav-item-2"><a href="language.html" >Python Language Services</a> &#187;</li>
  388. <li class="nav-item nav-item-this"><a href=""><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — Compile Python source files</a></li>
  389. <li class="right">
  390. <div class="inline-search" role="search">
  391. <form class="inline-search" action="../search.html" method="get">
  392. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  393. <input type="submit" value="Go" />
  394. </form>
  395. </div>
  396. |
  397. </li>
  398. <li class="right">
  399. <label class="theme-selector-label">
  400. Theme
  401. <select class="theme-selector" oninput="activateTheme(this.value)">
  402. <option value="auto" selected>Auto</option>
  403. <option value="light">Light</option>
  404. <option value="dark">Dark</option>
  405. </select>
  406. </label> |</li>
  407. </ul>
  408. </div>
  409. <div class="footer">
  410. &copy;
  411. <a href="../copyright.html">
  412. Copyright
  413. </a>
  414. 2001-2024, Python Software Foundation.
  415. <br />
  416. This page is licensed under the Python Software Foundation License Version 2.
  417. <br />
  418. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  419. <br />
  420. See <a href="/license.html">History and License</a> for more information.<br />
  421. <br />
  422. The Python Software Foundation is a non-profit corporation.
  423. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  424. <br />
  425. <br />
  426. Last updated on Apr 09, 2024 (13:47 UTC).
  427. <a href="/bugs.html">Found a bug</a>?
  428. <br />
  429. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  430. </div>
  431. </body>
  432. </html>
上海开阖软件有限公司 沪ICP备12045867号-1