parthtamu/rag-code-assistant
0
1<!DOCTYPE html>2 3<html lang="en" data-content_root="../">4 <head>5 <meta charset="utf-8" />6 <meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />7<meta property="og:title" content="py_compile — Compile Python source files" />8<meta property="og:type" content="website" />9<meta property="og:url" content="https://docs.python.org/3/library/py_compile.html" />10<meta property="og:site_name" content="Python documentation" />11<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..." />12<meta property="og:image:width" content="1146" />13<meta property="og:image:height" content="600" />14<meta property="og:image" content="https://docs.python.org/3.15/_images/social_previews/summary_library_py_compile_dae33c48.png" />15<meta property="og:image:alt" 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..." />16<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..." />17<meta name="twitter:card" content="summary_large_image" />18<meta name="theme-color" content="#3776ab">19 20 <title>py_compile — Compile Python source files — Python 3.15.0a6 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">21 22 <link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />23 <link rel="stylesheet" type="text/css" href="../_static/classic.css?v=234b1a7c" />24 <link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=89a2f22a" />25 <link rel="stylesheet" type="text/css" href="../_static/profiling-sampling-visualization.css?v=0c2600ae" />26 <link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />27 28 <script src="../_static/documentation_options.js?v=6b7c9ff5"></script>29 <script src="../_static/doctools.js?v=9bcbadda"></script>30 <script src="../_static/sphinx_highlight.js?v=dc90522c"></script>31 <script src="../_static/profiling-sampling-visualization.js?v=9811ed04"></script>32 33 <script src="../_static/sidebar.js"></script>34 35 <link rel="search" type="application/opensearchdescription+xml"36 title="Search within Python 3.15.0a6 documentation"37 href="../_static/opensearch.xml"/>38 <link rel="author" title="About these documents" href="../about.html" />39 <link rel="index" title="Index" href="../genindex.html" />40 <link rel="search" title="Search" href="../search.html" />41 <link rel="copyright" title="Copyright" href="../copyright.html" />42 <link rel="next" title="compileall — Byte-compile Python libraries" href="compileall.html" />43 <link rel="prev" title="pyclbr — Python module browser support" href="pyclbr.html" />44 45 46 <script defer file-types="bz2,epub,zip" data-domain="docs.python.org" src="https://analytics.python.org/js/script.file-downloads.outbound-links.js"></script>47 48 <link rel="canonical" href="https://docs.python.org/3/library/py_compile.html">49 50 51 52 53 <style>54 @media only screen {55 table.full-width-table {56 width: 100%;57 }58 }59 </style>60<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">61 <link rel="shortcut icon" type="image/png" href="../_static/py.svg">62 <script type="text/javascript" src="../_static/copybutton.js"></script>63 <script type="text/javascript" src="../_static/menu.js"></script>64 <script type="text/javascript" src="../_static/search-focus.js"></script>65 <script type="text/javascript" src="../_static/themetoggle.js"></script> 66 <script type="text/javascript" src="../_static/rtd_switcher.js"></script>67 <meta name="readthedocs-addons-api-version" content="1">68 69 </head>70<body>71<div class="mobile-nav">72 <input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"73 aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu">74 <nav class="nav-content" role="navigation">75 <label for="menuToggler" class="toggler__label">76 <span></span>77 </label>78 <span class="nav-items-wrapper">79 <a href="https://www.python.org/" class="nav-logo">80 <img src="../_static/py.svg" alt="Python logo">81 </a>82 <span class="version_switcher_placeholder"></span>83 <form role="search" class="search" action="../search.html" method="get">84 <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">85 <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>86 </svg>87 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q">88 <input type="submit" value="Go">89 </form>90 </span>91 </nav>92 <div class="menu-wrapper">93 <nav class="menu" role="navigation" aria-label="main navigation">94 <div class="language_switcher_placeholder"></div>95 96<label class="theme-selector-label">97 Theme98 <select class="theme-selector" oninput="activateTheme(this.value)">99 <option value="auto" selected>Auto</option>100 <option value="light">Light</option>101 <option value="dark">Dark</option>102 </select>103</label>104 <div>105 <h3><a href="../contents.html">Table of Contents</a></h3>106 <ul>107<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>108<li><a class="reference internal" href="#command-line-interface">Command-Line Interface</a></li>109</ul>110</li>111</ul>112 113 </div>114 <div>115 <h4>Previous topic</h4>116 <p class="topless"><a href="pyclbr.html"117 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pyclbr</span></code> — Python module browser support</a></p>118 </div>119 <div>120 <h4>Next topic</h4>121 <p class="topless"><a href="compileall.html"122 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a></p>123 </div>124 <script>125 document.addEventListener('DOMContentLoaded', () => {126 const title = document.querySelector('meta[property="og:title"]').content;127 const elements = document.querySelectorAll('.improvepage');128 const pageurl = window.location.href.split('?')[0];129 elements.forEach(element => {130 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));131 url.searchParams.set('pagetitle', title);132 url.searchParams.set('pageurl', pageurl);133 url.searchParams.set('pagesource', "library/py_compile.rst");134 element.href = url.toString();135 });136 });137 </script>138 <div role="note" aria-label="source link">139 <h3>This page</h3>140 <ul class="this-page-menu">141 <li><a href="../bugs.html">Report a bug</a></li>142 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>143 <li>144 <a href="https://github.com/python/cpython/blob/main/Doc/library/py_compile.rst?plain=1"145 rel="nofollow">Show source146 </a>147 </li>148 149 </ul>150 </div>151 </nav>152 </div>153</div>154 155 156 <div class="related" role="navigation" aria-label="Related">157 <h3>Navigation</h3>158 <ul>159 <li class="right" style="margin-right: 10px">160 <a href="../genindex.html" title="General Index"161 accesskey="I">index</a></li>162 <li class="right" >163 <a href="../py-modindex.html" title="Python Module Index"164 >modules</a> |</li>165 <li class="right" >166 <a href="compileall.html" title="compileall — Byte-compile Python libraries"167 accesskey="N">next</a> |</li>168 <li class="right" >169 <a href="pyclbr.html" title="pyclbr — Python module browser support"170 accesskey="P">previous</a> |</li>171 172 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>173 <li><a href="https://www.python.org/">Python</a> »</li>174 <li class="switchers">175 <div class="language_switcher_placeholder"></div>176 <div class="version_switcher_placeholder"></div>177 </li>178 <li>179 180 </li>181 <li id="cpython-language-and-version">182 <a href="../index.html">3.15.0a6 Documentation</a> »183 </li>184 185 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>186 <li class="nav-item nav-item-2"><a href="language.html" accesskey="U">Python Language Services</a> »</li>187 <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>188 <li class="right">189 190 191 <div class="inline-search" role="search">192 <form class="inline-search" action="../search.html" method="get">193 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">194 <input type="submit" value="Go">195 </form>196 </div>197 |198 </li>199 <li class="right">200<label class="theme-selector-label">201 Theme202 <select class="theme-selector" oninput="activateTheme(this.value)">203 <option value="auto" selected>Auto</option>204 <option value="light">Light</option>205 <option value="dark">Dark</option>206 </select>207</label> |</li>208 209 </ul>210 </div> 211 212 <div class="document">213 <div class="documentwrapper">214 <div class="bodywrapper">215 <div class="body" role="main">216 217 <section id="module-py_compile">218<span id="py-compile-compile-python-source-files"></span><h1><code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> — Compile Python source files<a class="headerlink" href="#module-py_compile" title="Link to this heading">¶</a></h1>219<p><strong>Source code:</strong> <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/main/Lib/py_compile.py">Lib/py_compile.py</a></p>220<hr class="docutils" id="index-0" />221<p>The <code class="xref py py-mod docutils literal notranslate"><span class="pre">py_compile</span></code> module provides a function to generate a byte-code file222from a source file, and another function used when the module source file is223invoked as a script.</p>224<p>Though not often needed, this function can be useful when installing modules for225shared use, especially if some of the users may not have permission to write the226byte-code cache files in the directory containing the source code.</p>227<dl class="py exception">228<dt class="sig sig-object py" id="py_compile.PyCompileError">229<em class="property"><span class="k"><span class="pre">exception</span></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>230<dd><p>Exception raised when an error occurs while attempting to compile the file.</p>231</dd></dl>232 233<dl class="py function">234<dt class="sig sig-object py" id="py_compile.compile">235<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>236<dd><p>Compile a source file to byte-code and write out the byte-code cache file.237The source code is loaded from the file named <em>file</em>. The byte-code is238written 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, ending239in <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>.240For 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 to241<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> is242specified, it is used instead of <em>file</em> as the name of the source file from243which source lines are obtained for display in exception tracebacks.244If <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 raised245when an error is encountered while compiling <em>file</em>. If <em>doraise</em> is false246(the default), an error string is written to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>, but no exception247is raised. This function returns the path to byte-compiled file, i.e.248whatever <em>cfile</em> value was used.</p>249<p>The <em>doraise</em> and <em>quiet</em> arguments determine how errors are handled while250compiling file. If <em>quiet</em> is 0 or 1, and <em>doraise</em> is false, the default251behaviour is enabled: an error string is written to <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>, and the252function returns <code class="docutils literal notranslate"><span class="pre">None</span></code> instead of a path. If <em>doraise</em> is true,253a <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,254no message is written, and <em>doraise</em> has no effect.</p>255<p>If the path that <em>cfile</em> becomes (either explicitly specified or computed)256is 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.257This is to act as a warning that import will turn those paths into regular258files if it is allowed to write byte-compiled files to those paths. This is259a side-effect of import using file renaming to place the final byte-compiled260file into place to prevent concurrent file writing issues.</p>261<p><em>optimize</em> controls the optimization level and is passed to the built-in262<code class="xref py py-func docutils literal notranslate"><span class="pre">compile()</span></code> function. The default of <code class="docutils literal notranslate"><span class="pre">-1</span></code> selects the optimization263level of the current interpreter.</p>264<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>265enum and controls how the generated bytecode cache is invalidated at266runtime. 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> if267the <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, otherwise268the 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>269<div class="versionchanged">270<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. Previous271default 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).272Also added the <em>optimize</em> parameter.</p>273</div>274<div class="versionchanged">275<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.276This means file creation/writing semantics now match what <code class="xref py py-mod docutils literal notranslate"><span class="pre">importlib</span></code>277does, e.g. permissions, write-and-move semantics, etc. Also added the278caveat 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 or279non-regular file.</p>280</div>281<div class="versionchanged">282<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>.283If 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,284<em>invalidation_mode</em> will be forced to285<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>286</div>287<div class="versionchanged">288<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 longer289overrides the value of the <em>invalidation_mode</em> argument, and determines290its default value instead.</p>291</div>292<div class="versionchanged">293<p><span class="versionmodified changed">Changed in version 3.8: </span>The <em>quiet</em> parameter was added.</p>294</div>295</dd></dl>296 297<dl class="py class">298<dt class="sig sig-object py" id="py_compile.PycInvalidationMode">299<em class="property"><span class="k"><span class="pre">class</span></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>300<dd><p>An enumeration of possible methods the interpreter can use to determine301whether a bytecode file is up to date with a source file. The <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file302indicates the desired invalidation mode in its header. See303<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 invalidates304<code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files at runtime.</p>305<div class="versionadded">306<p><span class="versionmodified added">Added in version 3.7.</span></p>307</div>308<dl class="py attribute">309<dt class="sig sig-object py" id="py_compile.PycInvalidationMode.TIMESTAMP">310<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>311<dd><p>The <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file includes the timestamp and size of the source file,312which Python will compare against the metadata of the source file at313runtime to determine if the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file needs to be regenerated.</p>314</dd></dl>315 316<dl class="py attribute">317<dt class="sig sig-object py" id="py_compile.PycInvalidationMode.CHECKED_HASH">318<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>319<dd><p>The <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file includes a hash of the source file content, which Python320will compare against the source at runtime to determine if the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code>321file needs to be regenerated.</p>322</dd></dl>323 324<dl class="py attribute">325<dt class="sig sig-object py" id="py_compile.PycInvalidationMode.UNCHECKED_HASH">326<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>327<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 source328file content. However, Python will at runtime assume the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> file is329up to date and not validate the <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> against the source file at all.</p>330<p>This option is useful when the <code class="docutils literal notranslate"><span class="pre">.pycs</span></code> are kept up to date by some331system external to Python like a build system.</p>332</dd></dl>333 334</dd></dl>335 336<section id="command-line-interface">337<span id="py-compile-cli"></span><h2>Command-Line Interface<a class="headerlink" href="#command-line-interface" title="Link to this heading">¶</a></h2>338<p>This module can be invoked as a script to compile several source339files. The files named in <em>filenames</em> are compiled and the resulting340bytecode is cached in the normal manner. This program does not search341a directory structure to locate source files; it only compiles files342named explicitly. The exit status is nonzero if one of the files could343not be compiled.</p>344<dl class="std option">345<dt class="sig sig-object std" id="cmdoption-python-m-py_compile-arg-file">346<span class="sig-name descname"><span class="pre"><file></span></span><span class="sig-prename descclassname"> <span class="pre">...</span> <span class="pre"><fileN></span></span><a class="headerlink" href="#cmdoption-python-m-py_compile-arg-file" title="Link to this definition">¶</a></dt>347<dt class="sig sig-object std" id="cmdoption-python-m-py_compile">348<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>349<dd><p>Positional arguments are files to compile. If <code class="docutils literal notranslate"><span class="pre">-</span></code> is the only350parameter, the list of files is taken from standard input.</p>351</dd></dl>352 353<dl class="std option">354<dt class="sig sig-object std" id="cmdoption-python-m-py_compile-q">355<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>356<dd><p>Suppress errors output.</p>357</dd></dl>358 359<div class="versionchanged">360<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>361</div>362<div class="versionchanged">363<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>364</div>365<div class="admonition seealso">366<p class="admonition-title">See also</p>367<dl class="simple">368<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>369</dd>370</dl>371</div>372</section>373</section>374 375 376 <div class="clearer"></div>377 </div>378 </div>379 </div>380 <div class="sphinxsidebar" role="navigation" aria-label="Main">381 <div class="sphinxsidebarwrapper">382 <div>383 <h3><a href="../contents.html">Table of Contents</a></h3>384 <ul>385<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>386<li><a class="reference internal" href="#command-line-interface">Command-Line Interface</a></li>387</ul>388</li>389</ul>390 391 </div>392 <div>393 <h4>Previous topic</h4>394 <p class="topless"><a href="pyclbr.html"395 title="previous chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">pyclbr</span></code> — Python module browser support</a></p>396 </div>397 <div>398 <h4>Next topic</h4>399 <p class="topless"><a href="compileall.html"400 title="next chapter"><code class="xref py py-mod docutils literal notranslate"><span class="pre">compileall</span></code> — Byte-compile Python libraries</a></p>401 </div>402 <script>403 document.addEventListener('DOMContentLoaded', () => {404 const title = document.querySelector('meta[property="og:title"]').content;405 const elements = document.querySelectorAll('.improvepage');406 const pageurl = window.location.href.split('?')[0];407 elements.forEach(element => {408 const url = new URL(element.href.split('?')[0].replace("-nojs", ""));409 url.searchParams.set('pagetitle', title);410 url.searchParams.set('pageurl', pageurl);411 url.searchParams.set('pagesource', "library/py_compile.rst");412 element.href = url.toString();413 });414 });415 </script>416 <div role="note" aria-label="source link">417 <h3>This page</h3>418 <ul class="this-page-menu">419 <li><a href="../bugs.html">Report a bug</a></li>420 <li><a class="improvepage" href="../improve-page-nojs.html">Improve this page</a></li>421 <li>422 <a href="https://github.com/python/cpython/blob/main/Doc/library/py_compile.rst?plain=1"423 rel="nofollow">Show source424 </a>425 </li>426 427 </ul>428 </div>429 </div>430<div id="sidebarbutton" title="Collapse sidebar">431<span>«</span>432</div>433 434 </div>435 <div class="clearer"></div>436 </div> 437 <div class="related" role="navigation" aria-label="Related">438 <h3>Navigation</h3>439 <ul>440 <li class="right" style="margin-right: 10px">441 <a href="../genindex.html" title="General Index"442 >index</a></li>443 <li class="right" >444 <a href="../py-modindex.html" title="Python Module Index"445 >modules</a> |</li>446 <li class="right" >447 <a href="compileall.html" title="compileall — Byte-compile Python libraries"448 >next</a> |</li>449 <li class="right" >450 <a href="pyclbr.html" title="pyclbr — Python module browser support"451 >previous</a> |</li>452 453 <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"></li>454 <li><a href="https://www.python.org/">Python</a> »</li>455 <li class="switchers">456 <div class="language_switcher_placeholder"></div>457 <div class="version_switcher_placeholder"></div>458 </li>459 <li>460 461 </li>462 <li id="cpython-language-and-version">463 <a href="../index.html">3.15.0a6 Documentation</a> »464 </li>465 466 <li class="nav-item nav-item-1"><a href="index.html" >The Python Standard Library</a> »</li>467 <li class="nav-item nav-item-2"><a href="language.html" >Python Language Services</a> »</li>468 <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>469 <li class="right">470 471 472 <div class="inline-search" role="search">473 <form class="inline-search" action="../search.html" method="get">474 <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box">475 <input type="submit" value="Go">476 </form>477 </div>478 |479 </li>480 <li class="right">481<label class="theme-selector-label">482 Theme483 <select class="theme-selector" oninput="activateTheme(this.value)">484 <option value="auto" selected>Auto</option>485 <option value="light">Light</option>486 <option value="dark">Dark</option>487 </select>488</label> |</li>489 490 </ul>491 </div> 492 <div class="footer">493 © <a href="../copyright.html">Copyright</a> 2001 Python Software Foundation.494 <br>495 This page is licensed under the Python Software Foundation License Version 2.496 <br>497 Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.498 <br>499 500 See <a href="/license.html">History and License</a> for more information.<br>501 502 503 <br>504 505 The Python Software Foundation is a non-profit corporation.506<a href="https://www.python.org/psf/donations/">Please donate.</a>507<br>508 <br>509 Last updated on Mar 10, 2026 (08:58 UTC).510 511 <a href="/bugs.html">Found a bug</a>?512 513 <br>514 515 Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.516 </div>517 518 </body>519</html>