gooderp18绿色标准版
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

1945 rindas
221KB

  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="Python Initialization Configuration" />
  7. <meta property="og:type" content="website" />
  8. <meta property="og:url" content="https://docs.python.org/3/c-api/init_config.html" />
  9. <meta property="og:site_name" content="Python documentation" />
  10. <meta property="og:description" content="Python can be initialized with Py_InitializeFromConfig() and the PyConfig structure. It can be preinitialized with Py_PreInitialize() and the PyPreConfig structure. There are two kinds of configura..." />
  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="Python can be initialized with Py_InitializeFromConfig() and the PyConfig structure. It can be preinitialized with Py_PreInitialize() and the PyPreConfig structure. There are two kinds of configura..." />
  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>Python Initialization Configuration &#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="Memory Management" href="memory.html" />
  33. <link rel="prev" title="Initialization, Finalization, and Threads" href="init.html" />
  34. <link rel="canonical" href="https://docs.python.org/3/c-api/init_config.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="#">Python Initialization Configuration</a><ul>
  86. <li><a class="reference internal" href="#example">Example</a></li>
  87. <li><a class="reference internal" href="#pywidestringlist">PyWideStringList</a></li>
  88. <li><a class="reference internal" href="#pystatus">PyStatus</a></li>
  89. <li><a class="reference internal" href="#pypreconfig">PyPreConfig</a></li>
  90. <li><a class="reference internal" href="#preinitialize-python-with-pypreconfig">Preinitialize Python with PyPreConfig</a></li>
  91. <li><a class="reference internal" href="#pyconfig">PyConfig</a></li>
  92. <li><a class="reference internal" href="#initialization-with-pyconfig">Initialization with PyConfig</a></li>
  93. <li><a class="reference internal" href="#isolated-configuration">Isolated Configuration</a></li>
  94. <li><a class="reference internal" href="#python-configuration">Python Configuration</a></li>
  95. <li><a class="reference internal" href="#python-path-configuration">Python Path Configuration</a></li>
  96. <li><a class="reference internal" href="#py-runmain">Py_RunMain()</a></li>
  97. <li><a class="reference internal" href="#py-getargcargv">Py_GetArgcArgv()</a></li>
  98. <li><a class="reference internal" href="#multi-phase-initialization-private-provisional-api">Multi-Phase Initialization Private Provisional API</a></li>
  99. </ul>
  100. </li>
  101. </ul>
  102. </div>
  103. <div>
  104. <h4>Previous topic</h4>
  105. <p class="topless"><a href="init.html"
  106. title="previous chapter">Initialization, Finalization, and Threads</a></p>
  107. </div>
  108. <div>
  109. <h4>Next topic</h4>
  110. <p class="topless"><a href="memory.html"
  111. title="next chapter">Memory Management</a></p>
  112. </div>
  113. <div role="note" aria-label="source link">
  114. <h3>This Page</h3>
  115. <ul class="this-page-menu">
  116. <li><a href="../bugs.html">Report a Bug</a></li>
  117. <li>
  118. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/init_config.rst"
  119. rel="nofollow">Show Source
  120. </a>
  121. </li>
  122. </ul>
  123. </div>
  124. </nav>
  125. </div>
  126. </div>
  127. <div class="related" role="navigation" aria-label="related navigation">
  128. <h3>Navigation</h3>
  129. <ul>
  130. <li class="right" style="margin-right: 10px">
  131. <a href="../genindex.html" title="General Index"
  132. accesskey="I">index</a></li>
  133. <li class="right" >
  134. <a href="../py-modindex.html" title="Python Module Index"
  135. >modules</a> |</li>
  136. <li class="right" >
  137. <a href="memory.html" title="Memory Management"
  138. accesskey="N">next</a> |</li>
  139. <li class="right" >
  140. <a href="init.html" title="Initialization, Finalization, and Threads"
  141. accesskey="P">previous</a> |</li>
  142. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  143. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  144. <li class="switchers">
  145. <div class="language_switcher_placeholder"></div>
  146. <div class="version_switcher_placeholder"></div>
  147. </li>
  148. <li>
  149. </li>
  150. <li id="cpython-language-and-version">
  151. <a href="../index.html">3.12.3 Documentation</a> &#187;
  152. </li>
  153. <li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python/C API Reference Manual</a> &#187;</li>
  154. <li class="nav-item nav-item-this"><a href="">Python Initialization Configuration</a></li>
  155. <li class="right">
  156. <div class="inline-search" role="search">
  157. <form class="inline-search" action="../search.html" method="get">
  158. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  159. <input type="submit" value="Go" />
  160. </form>
  161. </div>
  162. |
  163. </li>
  164. <li class="right">
  165. <label class="theme-selector-label">
  166. Theme
  167. <select class="theme-selector" oninput="activateTheme(this.value)">
  168. <option value="auto" selected>Auto</option>
  169. <option value="light">Light</option>
  170. <option value="dark">Dark</option>
  171. </select>
  172. </label> |</li>
  173. </ul>
  174. </div>
  175. <div class="document">
  176. <div class="documentwrapper">
  177. <div class="bodywrapper">
  178. <div class="body" role="main">
  179. <section id="python-initialization-configuration">
  180. <span id="init-config"></span><h1>Python Initialization Configuration<a class="headerlink" href="#python-initialization-configuration" title="Link to this heading">¶</a></h1>
  181. <div class="versionadded">
  182. <p><span class="versionmodified added">New in version 3.8.</span></p>
  183. </div>
  184. <p>Python can be initialized with <a class="reference internal" href="#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> and the
  185. <a class="reference internal" href="#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> structure. It can be preinitialized with
  186. <a class="reference internal" href="#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a> and the <a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a> structure.</p>
  187. <p>There are two kinds of configuration:</p>
  188. <ul class="simple">
  189. <li><p>The <a class="reference internal" href="#init-python-config"><span class="std std-ref">Python Configuration</span></a> can be used to build a
  190. customized Python which behaves as the regular Python. For example,
  191. environment variables and command line arguments are used to configure
  192. Python.</p></li>
  193. <li><p>The <a class="reference internal" href="#init-isolated-conf"><span class="std std-ref">Isolated Configuration</span></a> can be used to embed
  194. Python into an application. It isolates Python from the system. For example,
  195. environment variables are ignored, the LC_CTYPE locale is left unchanged and
  196. no signal handler is registered.</p></li>
  197. </ul>
  198. <p>The <a class="reference internal" href="#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a> function can be used to write a customized Python
  199. program.</p>
  200. <p>See also <a class="reference internal" href="init.html#initialization"><span class="std std-ref">Initialization, Finalization, and Threads</span></a>.</p>
  201. <div class="admonition seealso">
  202. <p class="admonition-title">See also</p>
  203. <p><span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0587/"><strong>PEP 587</strong></a> “Python Initialization Configuration”.</p>
  204. </div>
  205. <section id="example">
  206. <h2>Example<a class="headerlink" href="#example" title="Link to this heading">¶</a></h2>
  207. <p>Example of customized Python always running in isolated mode:</p>
  208. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="n">argv</span><span class="p">)</span>
  209. <span class="p">{</span>
  210. <span class="w"> </span><span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="p">;</span>
  211. <span class="w"> </span><span class="n">PyConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span>
  212. <span class="w"> </span><span class="n">PyConfig_InitPythonConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  213. <span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">isolated</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
  214. <span class="w"> </span><span class="cm">/* Decode command line arguments.</span>
  215. <span class="cm"> Implicitly preinitialize Python (in isolated mode). */</span>
  216. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyConfig_SetBytesArgv</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">,</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="n">argv</span><span class="p">);</span>
  217. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  218. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">exception</span><span class="p">;</span>
  219. <span class="w"> </span><span class="p">}</span>
  220. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_InitializeFromConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  221. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  222. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">exception</span><span class="p">;</span>
  223. <span class="w"> </span><span class="p">}</span>
  224. <span class="w"> </span><span class="n">PyConfig_Clear</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  225. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">Py_RunMain</span><span class="p">();</span>
  226. <span class="nl">exception</span><span class="p">:</span>
  227. <span class="w"> </span><span class="n">PyConfig_Clear</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  228. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_IsExit</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  229. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">status</span><span class="p">.</span><span class="n">exitcode</span><span class="p">;</span>
  230. <span class="w"> </span><span class="p">}</span>
  231. <span class="w"> </span><span class="cm">/* Display the error message and exit the process with</span>
  232. <span class="cm"> non-zero exit code */</span>
  233. <span class="w"> </span><span class="n">Py_ExitStatusException</span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
  234. <span class="p">}</span>
  235. </pre></div>
  236. </div>
  237. </section>
  238. <section id="pywidestringlist">
  239. <h2>PyWideStringList<a class="headerlink" href="#pywidestringlist" title="Link to this heading">¶</a></h2>
  240. <dl class="c type">
  241. <dt class="sig sig-object c" id="c.PyWideStringList">
  242. <span class="k"><span class="pre">type</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyWideStringList</span></span></span><a class="headerlink" href="#c.PyWideStringList" title="Link to this definition">¶</a><br /></dt>
  243. <dd><p>List of <code class="docutils literal notranslate"><span class="pre">wchar_t*</span></code> strings.</p>
  244. <p>If <em>length</em> is non-zero, <em>items</em> must be non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code> and all strings must be
  245. non-<code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  246. <p>Methods:</p>
  247. <dl class="c function">
  248. <dt class="sig sig-object c" id="c.PyWideStringList_Append">
  249. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyWideStringList_Append</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">list</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">item</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyWideStringList_Append" title="Link to this definition">¶</a><br /></dt>
  250. <dd><p>Append <em>item</em> to <em>list</em>.</p>
  251. <p>Python must be preinitialized to call this function.</p>
  252. </dd></dl>
  253. <dl class="c function">
  254. <dt class="sig sig-object c" id="c.PyWideStringList_Insert">
  255. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyWideStringList_Insert</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">list</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">index</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">item</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyWideStringList_Insert" title="Link to this definition">¶</a><br /></dt>
  256. <dd><p>Insert <em>item</em> into <em>list</em> at <em>index</em>.</p>
  257. <p>If <em>index</em> is greater than or equal to <em>list</em> length, append <em>item</em> to
  258. <em>list</em>.</p>
  259. <p><em>index</em> must be greater than or equal to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  260. <p>Python must be preinitialized to call this function.</p>
  261. </dd></dl>
  262. <p>Structure fields:</p>
  263. <dl class="c member">
  264. <dt class="sig sig-object c" id="c.PyWideStringList.length">
  265. <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">length</span></span></span><a class="headerlink" href="#c.PyWideStringList.length" title="Link to this definition">¶</a><br /></dt>
  266. <dd><p>List length.</p>
  267. </dd></dl>
  268. <dl class="c member">
  269. <dt class="sig sig-object c" id="c.PyWideStringList.items">
  270. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">items</span></span></span><a class="headerlink" href="#c.PyWideStringList.items" title="Link to this definition">¶</a><br /></dt>
  271. <dd><p>List items.</p>
  272. </dd></dl>
  273. </dd></dl>
  274. </section>
  275. <section id="pystatus">
  276. <h2>PyStatus<a class="headerlink" href="#pystatus" title="Link to this heading">¶</a></h2>
  277. <dl class="c type">
  278. <dt class="sig sig-object c" id="c.PyStatus">
  279. <span class="k"><span class="pre">type</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus</span></span></span><a class="headerlink" href="#c.PyStatus" title="Link to this definition">¶</a><br /></dt>
  280. <dd><p>Structure to store an initialization function status: success, error
  281. or exit.</p>
  282. <p>For an error, it can store the C function name which created the error.</p>
  283. <p>Structure fields:</p>
  284. <dl class="c member">
  285. <dt class="sig sig-object c" id="c.PyStatus.exitcode">
  286. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">exitcode</span></span></span><a class="headerlink" href="#c.PyStatus.exitcode" title="Link to this definition">¶</a><br /></dt>
  287. <dd><p>Exit code. Argument passed to <code class="docutils literal notranslate"><span class="pre">exit()</span></code>.</p>
  288. </dd></dl>
  289. <dl class="c member">
  290. <dt class="sig sig-object c" id="c.PyStatus.err_msg">
  291. <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">err_msg</span></span></span><a class="headerlink" href="#c.PyStatus.err_msg" title="Link to this definition">¶</a><br /></dt>
  292. <dd><p>Error message.</p>
  293. </dd></dl>
  294. <dl class="c member">
  295. <dt class="sig sig-object c" id="c.PyStatus.func">
  296. <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">func</span></span></span><a class="headerlink" href="#c.PyStatus.func" title="Link to this definition">¶</a><br /></dt>
  297. <dd><p>Name of the function which created an error, can be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  298. </dd></dl>
  299. <p>Functions to create a status:</p>
  300. <dl class="c function">
  301. <dt class="sig sig-object c" id="c.PyStatus_Ok">
  302. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus_Ok</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStatus_Ok" title="Link to this definition">¶</a><br /></dt>
  303. <dd><p>Success.</p>
  304. </dd></dl>
  305. <dl class="c function">
  306. <dt class="sig sig-object c" id="c.PyStatus_Error">
  307. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus_Error</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">err_msg</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStatus_Error" title="Link to this definition">¶</a><br /></dt>
  308. <dd><p>Initialization error with a message.</p>
  309. <p><em>err_msg</em> must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  310. </dd></dl>
  311. <dl class="c function">
  312. <dt class="sig sig-object c" id="c.PyStatus_NoMemory">
  313. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus_NoMemory</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStatus_NoMemory" title="Link to this definition">¶</a><br /></dt>
  314. <dd><p>Memory allocation failure (out of memory).</p>
  315. </dd></dl>
  316. <dl class="c function">
  317. <dt class="sig sig-object c" id="c.PyStatus_Exit">
  318. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus_Exit</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">exitcode</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStatus_Exit" title="Link to this definition">¶</a><br /></dt>
  319. <dd><p>Exit Python with the specified exit code.</p>
  320. </dd></dl>
  321. <p>Functions to handle a status:</p>
  322. <dl class="c function">
  323. <dt class="sig sig-object c" id="c.PyStatus_Exception">
  324. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus_Exception</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="n"><span class="pre">status</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStatus_Exception" title="Link to this definition">¶</a><br /></dt>
  325. <dd><p>Is the status an error or an exit? If true, the exception must be
  326. handled; by calling <a class="reference internal" href="#c.Py_ExitStatusException" title="Py_ExitStatusException"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_ExitStatusException()</span></code></a> for example.</p>
  327. </dd></dl>
  328. <dl class="c function">
  329. <dt class="sig sig-object c" id="c.PyStatus_IsError">
  330. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus_IsError</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="n"><span class="pre">status</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStatus_IsError" title="Link to this definition">¶</a><br /></dt>
  331. <dd><p>Is the result an error?</p>
  332. </dd></dl>
  333. <dl class="c function">
  334. <dt class="sig sig-object c" id="c.PyStatus_IsExit">
  335. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyStatus_IsExit</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="n"><span class="pre">status</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyStatus_IsExit" title="Link to this definition">¶</a><br /></dt>
  336. <dd><p>Is the result an exit?</p>
  337. </dd></dl>
  338. <dl class="c function">
  339. <dt class="sig sig-object c" id="c.Py_ExitStatusException">
  340. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_ExitStatusException</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="n"><span class="pre">status</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_ExitStatusException" title="Link to this definition">¶</a><br /></dt>
  341. <dd><p>Call <code class="docutils literal notranslate"><span class="pre">exit(exitcode)</span></code> if <em>status</em> is an exit. Print the error
  342. message and exit with a non-zero exit code if <em>status</em> is an error. Must
  343. only be called if <code class="docutils literal notranslate"><span class="pre">PyStatus_Exception(status)</span></code> is non-zero.</p>
  344. </dd></dl>
  345. </dd></dl>
  346. <div class="admonition note">
  347. <p class="admonition-title">Note</p>
  348. <p>Internally, Python uses macros which set <code class="docutils literal notranslate"><span class="pre">PyStatus.func</span></code>,
  349. whereas functions to create a status set <code class="docutils literal notranslate"><span class="pre">func</span></code> to <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  350. </div>
  351. <p>Example:</p>
  352. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyStatus</span><span class="w"> </span><span class="nf">alloc</span><span class="p">(</span><span class="kt">void</span><span class="w"> </span><span class="o">**</span><span class="n">ptr</span><span class="p">,</span><span class="w"> </span><span class="kt">size_t</span><span class="w"> </span><span class="n">size</span><span class="p">)</span>
  353. <span class="p">{</span>
  354. <span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyMem_RawMalloc</span><span class="p">(</span><span class="n">size</span><span class="p">);</span>
  355. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="o">*</span><span class="n">ptr</span><span class="w"> </span><span class="o">==</span><span class="w"> </span><span class="nb">NULL</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  356. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">PyStatus_NoMemory</span><span class="p">();</span>
  357. <span class="w"> </span><span class="p">}</span>
  358. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">PyStatus_Ok</span><span class="p">();</span>
  359. <span class="p">}</span>
  360. <span class="kt">int</span><span class="w"> </span><span class="nf">main</span><span class="p">(</span><span class="kt">int</span><span class="w"> </span><span class="n">argc</span><span class="p">,</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">**</span><span class="n">argv</span><span class="p">)</span>
  361. <span class="p">{</span>
  362. <span class="w"> </span><span class="kt">void</span><span class="w"> </span><span class="o">*</span><span class="n">ptr</span><span class="p">;</span>
  363. <span class="w"> </span><span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">alloc</span><span class="p">(</span><span class="o">&amp;</span><span class="n">ptr</span><span class="p">,</span><span class="w"> </span><span class="mi">16</span><span class="p">);</span>
  364. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  365. <span class="w"> </span><span class="n">Py_ExitStatusException</span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
  366. <span class="w"> </span><span class="p">}</span>
  367. <span class="w"> </span><span class="n">PyMem_Free</span><span class="p">(</span><span class="n">ptr</span><span class="p">);</span>
  368. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
  369. <span class="p">}</span>
  370. </pre></div>
  371. </div>
  372. </section>
  373. <section id="pypreconfig">
  374. <h2>PyPreConfig<a class="headerlink" href="#pypreconfig" title="Link to this heading">¶</a></h2>
  375. <dl class="c type">
  376. <dt class="sig sig-object c" id="c.PyPreConfig">
  377. <span class="k"><span class="pre">type</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyPreConfig</span></span></span><a class="headerlink" href="#c.PyPreConfig" title="Link to this definition">¶</a><br /></dt>
  378. <dd><p>Structure used to preinitialize Python.</p>
  379. <p>Function to initialize a preconfiguration:</p>
  380. <dl class="c function">
  381. <dt class="sig sig-object c" id="c.PyPreConfig_InitPythonConfig">
  382. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyPreConfig_InitPythonConfig</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><span class="n"><span class="pre">PyPreConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">preconfig</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyPreConfig_InitPythonConfig" title="Link to this definition">¶</a><br /></dt>
  383. <dd><p>Initialize the preconfiguration with <a class="reference internal" href="#init-python-config"><span class="std std-ref">Python Configuration</span></a>.</p>
  384. </dd></dl>
  385. <dl class="c function">
  386. <dt class="sig sig-object c" id="c.PyPreConfig_InitIsolatedConfig">
  387. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyPreConfig_InitIsolatedConfig</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><span class="n"><span class="pre">PyPreConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">preconfig</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyPreConfig_InitIsolatedConfig" title="Link to this definition">¶</a><br /></dt>
  388. <dd><p>Initialize the preconfiguration with <a class="reference internal" href="#init-isolated-conf"><span class="std std-ref">Isolated Configuration</span></a>.</p>
  389. </dd></dl>
  390. <p>Structure fields:</p>
  391. <dl class="c member">
  392. <dt class="sig sig-object c" id="c.PyPreConfig.allocator">
  393. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">allocator</span></span></span><a class="headerlink" href="#c.PyPreConfig.allocator" title="Link to this definition">¶</a><br /></dt>
  394. <dd><p>Name of the Python memory allocators:</p>
  395. <ul class="simple">
  396. <li><p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_NOT_SET</span></code> (<code class="docutils literal notranslate"><span class="pre">0</span></code>): don’t change memory allocators
  397. (use defaults).</p></li>
  398. <li><p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_DEFAULT</span></code> (<code class="docutils literal notranslate"><span class="pre">1</span></code>): <a class="reference internal" href="memory.html#default-memory-allocators"><span class="std std-ref">default memory allocators</span></a>.</p></li>
  399. <li><p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_DEBUG</span></code> (<code class="docutils literal notranslate"><span class="pre">2</span></code>): <a class="reference internal" href="memory.html#default-memory-allocators"><span class="std std-ref">default memory allocators</span></a> with <a class="reference internal" href="memory.html#pymem-debug-hooks"><span class="std std-ref">debug hooks</span></a>.</p></li>
  400. <li><p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_MALLOC</span></code> (<code class="docutils literal notranslate"><span class="pre">3</span></code>): use <code class="docutils literal notranslate"><span class="pre">malloc()</span></code> of the C library.</p></li>
  401. <li><p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_MALLOC_DEBUG</span></code> (<code class="docutils literal notranslate"><span class="pre">4</span></code>): force usage of
  402. <code class="docutils literal notranslate"><span class="pre">malloc()</span></code> with <a class="reference internal" href="memory.html#pymem-debug-hooks"><span class="std std-ref">debug hooks</span></a>.</p></li>
  403. <li><p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_PYMALLOC</span></code> (<code class="docutils literal notranslate"><span class="pre">5</span></code>): <a class="reference internal" href="memory.html#pymalloc"><span class="std std-ref">Python pymalloc memory
  404. allocator</span></a>.</p></li>
  405. <li><p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_PYMALLOC_DEBUG</span></code> (<code class="docutils literal notranslate"><span class="pre">6</span></code>): <a class="reference internal" href="memory.html#pymalloc"><span class="std std-ref">Python pymalloc
  406. memory allocator</span></a> with <a class="reference internal" href="memory.html#pymem-debug-hooks"><span class="std std-ref">debug hooks</span></a>.</p></li>
  407. </ul>
  408. <p><code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_PYMALLOC</span></code> and <code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_PYMALLOC_DEBUG</span></code> are
  409. not supported if Python is <a class="reference internal" href="../using/configure.html#cmdoption-without-pymalloc"><code class="xref std std-option docutils literal notranslate"><span class="pre">configured</span> <span class="pre">using</span> <span class="pre">--without-pymalloc</span></code></a>.</p>
  410. <p>See <a class="reference internal" href="memory.html#memory"><span class="std std-ref">Memory Management</span></a>.</p>
  411. <p>Default: <code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_NOT_SET</span></code>.</p>
  412. </dd></dl>
  413. <dl class="c member">
  414. <dt class="sig sig-object c" id="c.PyPreConfig.configure_locale">
  415. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">configure_locale</span></span></span><a class="headerlink" href="#c.PyPreConfig.configure_locale" title="Link to this definition">¶</a><br /></dt>
  416. <dd><p>Set the LC_CTYPE locale to the user preferred locale.</p>
  417. <p>If equals to <code class="docutils literal notranslate"><span class="pre">0</span></code>, set <a class="reference internal" href="#c.PyPreConfig.coerce_c_locale" title="PyPreConfig.coerce_c_locale"><code class="xref c c-member docutils literal notranslate"><span class="pre">coerce_c_locale</span></code></a> and
  418. <a class="reference internal" href="#c.PyPreConfig.coerce_c_locale_warn" title="PyPreConfig.coerce_c_locale_warn"><code class="xref c c-member docutils literal notranslate"><span class="pre">coerce_c_locale_warn</span></code></a> members to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  419. <p>See the <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a>.</p>
  420. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python config, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  421. </dd></dl>
  422. <dl class="c member">
  423. <dt class="sig sig-object c" id="c.PyPreConfig.coerce_c_locale">
  424. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">coerce_c_locale</span></span></span><a class="headerlink" href="#c.PyPreConfig.coerce_c_locale" title="Link to this definition">¶</a><br /></dt>
  425. <dd><p>If equals to <code class="docutils literal notranslate"><span class="pre">2</span></code>, coerce the C locale.</p>
  426. <p>If equals to <code class="docutils literal notranslate"><span class="pre">1</span></code>, read the LC_CTYPE locale to decide if it should be
  427. coerced.</p>
  428. <p>See the <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a>.</p>
  429. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python config, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  430. </dd></dl>
  431. <dl class="c member">
  432. <dt class="sig sig-object c" id="c.PyPreConfig.coerce_c_locale_warn">
  433. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">coerce_c_locale_warn</span></span></span><a class="headerlink" href="#c.PyPreConfig.coerce_c_locale_warn" title="Link to this definition">¶</a><br /></dt>
  434. <dd><p>If non-zero, emit a warning if the C locale is coerced.</p>
  435. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python config, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  436. </dd></dl>
  437. <dl class="c member">
  438. <dt class="sig sig-object c" id="c.PyPreConfig.dev_mode">
  439. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">dev_mode</span></span></span><a class="headerlink" href="#c.PyPreConfig.dev_mode" title="Link to this definition">¶</a><br /></dt>
  440. <dd><p><a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a>: see
  441. <a class="reference internal" href="#c.PyConfig.dev_mode" title="PyConfig.dev_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.dev_mode</span></code></a>.</p>
  442. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  443. </dd></dl>
  444. <dl class="c member">
  445. <dt class="sig sig-object c" id="c.PyPreConfig.isolated">
  446. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">isolated</span></span></span><a class="headerlink" href="#c.PyPreConfig.isolated" title="Link to this definition">¶</a><br /></dt>
  447. <dd><p>Isolated mode: see <a class="reference internal" href="#c.PyConfig.isolated" title="PyConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.isolated</span></code></a>.</p>
  448. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">1</span></code> in isolated mode.</p>
  449. </dd></dl>
  450. <dl class="c member">
  451. <dt class="sig sig-object c" id="c.PyPreConfig.legacy_windows_fs_encoding">
  452. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">legacy_windows_fs_encoding</span></span></span><a class="headerlink" href="#c.PyPreConfig.legacy_windows_fs_encoding" title="Link to this definition">¶</a><br /></dt>
  453. <dd><p>If non-zero:</p>
  454. <ul class="simple">
  455. <li><p>Set <a class="reference internal" href="#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a> to <code class="docutils literal notranslate"><span class="pre">0</span></code>,</p></li>
  456. <li><p>Set <a class="reference internal" href="#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_encoding</span></code></a> to <code class="docutils literal notranslate"><span class="pre">&quot;mbcs&quot;</span></code>,</p></li>
  457. <li><p>Set <a class="reference internal" href="#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.filesystem_errors</span></code></a> to <code class="docutils literal notranslate"><span class="pre">&quot;replace&quot;</span></code>.</p></li>
  458. </ul>
  459. <p>Initialized the from <span class="target" id="index-1"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSFSENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSFSENCODING</span></code></a> environment
  460. variable value.</p>
  461. <p>Only available on Windows. <code class="docutils literal notranslate"><span class="pre">#ifdef</span> <span class="pre">MS_WINDOWS</span></code> macro can be used for
  462. Windows specific code.</p>
  463. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  464. </dd></dl>
  465. <dl class="c member">
  466. <dt class="sig sig-object c" id="c.PyPreConfig.parse_argv">
  467. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">parse_argv</span></span></span><a class="headerlink" href="#c.PyPreConfig.parse_argv" title="Link to this definition">¶</a><br /></dt>
  468. <dd><p>If non-zero, <a class="reference internal" href="#c.Py_PreInitializeFromArgs" title="Py_PreInitializeFromArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitializeFromArgs()</span></code></a> and
  469. <a class="reference internal" href="#c.Py_PreInitializeFromBytesArgs" title="Py_PreInitializeFromBytesArgs"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitializeFromBytesArgs()</span></code></a> parse their <code class="docutils literal notranslate"><span class="pre">argv</span></code> argument the
  470. same way the regular Python parses command line arguments: see
  471. <a class="reference internal" href="../using/cmdline.html#using-on-cmdline"><span class="std std-ref">Command Line Arguments</span></a>.</p>
  472. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python config, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  473. </dd></dl>
  474. <dl class="c member">
  475. <dt class="sig sig-object c" id="c.PyPreConfig.use_environment">
  476. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">use_environment</span></span></span><a class="headerlink" href="#c.PyPreConfig.use_environment" title="Link to this definition">¶</a><br /></dt>
  477. <dd><p>Use <a class="reference internal" href="../using/cmdline.html#using-on-envvars"><span class="std std-ref">environment variables</span></a>? See
  478. <a class="reference internal" href="#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_environment</span></code></a>.</p>
  479. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python config and <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  480. </dd></dl>
  481. <dl class="c member">
  482. <dt class="sig sig-object c" id="c.PyPreConfig.utf8_mode">
  483. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">utf8_mode</span></span></span><a class="headerlink" href="#c.PyPreConfig.utf8_mode" title="Link to this definition">¶</a><br /></dt>
  484. <dd><p>If non-zero, enable the <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>.</p>
  485. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> or <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">utf8</span></code></a> command line option
  486. and the <span class="target" id="index-2"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUTF8"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUTF8</span></code></a> environment variable.</p>
  487. <p>Also set to <code class="docutils literal notranslate"><span class="pre">1</span></code> if the <code class="docutils literal notranslate"><span class="pre">LC_CTYPE</span></code> locale is <code class="docutils literal notranslate"><span class="pre">C</span></code> or <code class="docutils literal notranslate"><span class="pre">POSIX</span></code>.</p>
  488. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python config and <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  489. </dd></dl>
  490. </dd></dl>
  491. </section>
  492. <section id="preinitialize-python-with-pypreconfig">
  493. <span id="c-preinit"></span><h2>Preinitialize Python with PyPreConfig<a class="headerlink" href="#preinitialize-python-with-pypreconfig" title="Link to this heading">¶</a></h2>
  494. <p>The preinitialization of Python:</p>
  495. <ul class="simple">
  496. <li><p>Set the Python memory allocators (<a class="reference internal" href="#c.PyPreConfig.allocator" title="PyPreConfig.allocator"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.allocator</span></code></a>)</p></li>
  497. <li><p>Configure the LC_CTYPE locale (<a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a>)</p></li>
  498. <li><p>Set the <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>
  499. (<a class="reference internal" href="#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a>)</p></li>
  500. </ul>
  501. <p>The current preconfiguration (<code class="docutils literal notranslate"><span class="pre">PyPreConfig</span></code> type) is stored in
  502. <code class="docutils literal notranslate"><span class="pre">_PyRuntime.preconfig</span></code>.</p>
  503. <p>Functions to preinitialize Python:</p>
  504. <dl class="c function">
  505. <dt class="sig sig-object c" id="c.Py_PreInitialize">
  506. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_PreInitialize</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><span class="n"><span class="pre">PyPreConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">preconfig</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_PreInitialize" title="Link to this definition">¶</a><br /></dt>
  507. <dd><p>Preinitialize Python from <em>preconfig</em> preconfiguration.</p>
  508. <p><em>preconfig</em> must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  509. </dd></dl>
  510. <dl class="c function">
  511. <dt class="sig sig-object c" id="c.Py_PreInitializeFromBytesArgs">
  512. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_PreInitializeFromBytesArgs</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><span class="n"><span class="pre">PyPreConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">preconfig</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argc</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_PreInitializeFromBytesArgs" title="Link to this definition">¶</a><br /></dt>
  513. <dd><p>Preinitialize Python from <em>preconfig</em> preconfiguration.</p>
  514. <p>Parse <em>argv</em> command line arguments (bytes strings) if
  515. <a class="reference internal" href="#c.PyPreConfig.parse_argv" title="PyPreConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">parse_argv</span></code></a> of <em>preconfig</em> is non-zero.</p>
  516. <p><em>preconfig</em> must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  517. </dd></dl>
  518. <dl class="c function">
  519. <dt class="sig sig-object c" id="c.Py_PreInitializeFromArgs">
  520. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_PreInitializeFromArgs</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><span class="n"><span class="pre">PyPreConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">preconfig</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argc</span></span>, <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_PreInitializeFromArgs" title="Link to this definition">¶</a><br /></dt>
  521. <dd><p>Preinitialize Python from <em>preconfig</em> preconfiguration.</p>
  522. <p>Parse <em>argv</em> command line arguments (wide strings) if
  523. <a class="reference internal" href="#c.PyPreConfig.parse_argv" title="PyPreConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">parse_argv</span></code></a> of <em>preconfig</em> is non-zero.</p>
  524. <p><em>preconfig</em> must not be <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  525. </dd></dl>
  526. <p>The caller is responsible to handle exceptions (error or exit) using
  527. <a class="reference internal" href="#c.PyStatus_Exception" title="PyStatus_Exception"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Exception()</span></code></a> and <a class="reference internal" href="#c.Py_ExitStatusException" title="Py_ExitStatusException"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_ExitStatusException()</span></code></a>.</p>
  528. <p>For <a class="reference internal" href="#init-python-config"><span class="std std-ref">Python Configuration</span></a>
  529. (<a class="reference internal" href="#c.PyPreConfig_InitPythonConfig" title="PyPreConfig_InitPythonConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyPreConfig_InitPythonConfig()</span></code></a>), if Python is initialized with
  530. command line arguments, the command line arguments must also be passed to
  531. preinitialize Python, since they have an effect on the pre-configuration
  532. like encodings. For example, the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">utf8</span></code></a> command line option
  533. enables the <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>.</p>
  534. <p><code class="docutils literal notranslate"><span class="pre">PyMem_SetAllocator()</span></code> can be called after <a class="reference internal" href="#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a> and
  535. before <a class="reference internal" href="#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> to install a custom memory allocator.
  536. It can be called before <a class="reference internal" href="#c.Py_PreInitialize" title="Py_PreInitialize"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_PreInitialize()</span></code></a> if
  537. <a class="reference internal" href="#c.PyPreConfig.allocator" title="PyPreConfig.allocator"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.allocator</span></code></a> is set to <code class="docutils literal notranslate"><span class="pre">PYMEM_ALLOCATOR_NOT_SET</span></code>.</p>
  538. <p>Python memory allocation functions like <a class="reference internal" href="memory.html#c.PyMem_RawMalloc" title="PyMem_RawMalloc"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyMem_RawMalloc()</span></code></a> must not be
  539. used before the Python preinitialization, whereas calling directly <code class="docutils literal notranslate"><span class="pre">malloc()</span></code>
  540. and <code class="docutils literal notranslate"><span class="pre">free()</span></code> is always safe. <a class="reference internal" href="sys.html#c.Py_DecodeLocale" title="Py_DecodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecodeLocale()</span></code></a> must not be called
  541. before the Python preinitialization.</p>
  542. <p>Example using the preinitialization to enable
  543. the <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>:</p>
  544. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="p">;</span>
  545. <span class="n">PyPreConfig</span><span class="w"> </span><span class="n">preconfig</span><span class="p">;</span>
  546. <span class="n">PyPreConfig_InitPythonConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">preconfig</span><span class="p">);</span>
  547. <span class="n">preconfig</span><span class="p">.</span><span class="n">utf8_mode</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
  548. <span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_PreInitialize</span><span class="p">(</span><span class="o">&amp;</span><span class="n">preconfig</span><span class="p">);</span>
  549. <span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  550. <span class="w"> </span><span class="n">Py_ExitStatusException</span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
  551. <span class="p">}</span>
  552. <span class="cm">/* at this point, Python speaks UTF-8 */</span>
  553. <span class="n">Py_Initialize</span><span class="p">();</span>
  554. <span class="cm">/* ... use Python API here ... */</span>
  555. <span class="n">Py_Finalize</span><span class="p">();</span>
  556. </pre></div>
  557. </div>
  558. </section>
  559. <section id="pyconfig">
  560. <h2>PyConfig<a class="headerlink" href="#pyconfig" title="Link to this heading">¶</a></h2>
  561. <dl class="c type">
  562. <dt class="sig sig-object c" id="c.PyConfig">
  563. <span class="k"><span class="pre">type</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig</span></span></span><a class="headerlink" href="#c.PyConfig" title="Link to this definition">¶</a><br /></dt>
  564. <dd><p>Structure containing most parameters to configure Python.</p>
  565. <p>When done, the <a class="reference internal" href="#c.PyConfig_Clear" title="PyConfig_Clear"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Clear()</span></code></a> function must be used to release the
  566. configuration memory.</p>
  567. <p>Structure methods:</p>
  568. <dl class="c function">
  569. <dt class="sig sig-object c" id="c.PyConfig_InitPythonConfig">
  570. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_InitPythonConfig</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_InitPythonConfig" title="Link to this definition">¶</a><br /></dt>
  571. <dd><p>Initialize configuration with the <a class="reference internal" href="#init-python-config"><span class="std std-ref">Python Configuration</span></a>.</p>
  572. </dd></dl>
  573. <dl class="c function">
  574. <dt class="sig sig-object c" id="c.PyConfig_InitIsolatedConfig">
  575. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_InitIsolatedConfig</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_InitIsolatedConfig" title="Link to this definition">¶</a><br /></dt>
  576. <dd><p>Initialize configuration with the <a class="reference internal" href="#init-isolated-conf"><span class="std std-ref">Isolated Configuration</span></a>.</p>
  577. </dd></dl>
  578. <dl class="c function">
  579. <dt class="sig sig-object c" id="c.PyConfig_SetString">
  580. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_SetString</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span>, <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config_str</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_SetString" title="Link to this definition">¶</a><br /></dt>
  581. <dd><p>Copy the wide character string <em>str</em> into <code class="docutils literal notranslate"><span class="pre">*config_str</span></code>.</p>
  582. <p><a class="reference internal" href="#c-preinit"><span class="std std-ref">Preinitialize Python</span></a> if needed.</p>
  583. </dd></dl>
  584. <dl class="c function">
  585. <dt class="sig sig-object c" id="c.PyConfig_SetBytesString">
  586. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_SetBytesString</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span>, <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config_str</span></span>, <span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">str</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_SetBytesString" title="Link to this definition">¶</a><br /></dt>
  587. <dd><p>Decode <em>str</em> using <a class="reference internal" href="sys.html#c.Py_DecodeLocale" title="Py_DecodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecodeLocale()</span></code></a> and set the result into
  588. <code class="docutils literal notranslate"><span class="pre">*config_str</span></code>.</p>
  589. <p><a class="reference internal" href="#c-preinit"><span class="std std-ref">Preinitialize Python</span></a> if needed.</p>
  590. </dd></dl>
  591. <dl class="c function">
  592. <dt class="sig sig-object c" id="c.PyConfig_SetArgv">
  593. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_SetArgv</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argc</span></span>, <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_SetArgv" title="Link to this definition">¶</a><br /></dt>
  594. <dd><p>Set command line arguments (<a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> member of
  595. <em>config</em>) from the <em>argv</em> list of wide character strings.</p>
  596. <p><a class="reference internal" href="#c-preinit"><span class="std std-ref">Preinitialize Python</span></a> if needed.</p>
  597. </dd></dl>
  598. <dl class="c function">
  599. <dt class="sig sig-object c" id="c.PyConfig_SetBytesArgv">
  600. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_SetBytesArgv</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span>, <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="n"><span class="pre">argc</span></span>, <span class="kt"><span class="pre">char</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="k"><span class="pre">const</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_SetBytesArgv" title="Link to this definition">¶</a><br /></dt>
  601. <dd><p>Set command line arguments (<a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> member of
  602. <em>config</em>) from the <em>argv</em> list of bytes strings. Decode bytes using
  603. <a class="reference internal" href="sys.html#c.Py_DecodeLocale" title="Py_DecodeLocale"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_DecodeLocale()</span></code></a>.</p>
  604. <p><a class="reference internal" href="#c-preinit"><span class="std std-ref">Preinitialize Python</span></a> if needed.</p>
  605. </dd></dl>
  606. <dl class="c function">
  607. <dt class="sig sig-object c" id="c.PyConfig_SetWideStringList">
  608. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_SetWideStringList</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span>, <a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">list</span></span>, <a class="reference internal" href="intro.html#c.Py_ssize_t" title="Py_ssize_t"><span class="n"><span class="pre">Py_ssize_t</span></span></a><span class="w"> </span><span class="n"><span class="pre">length</span></span>, <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">items</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_SetWideStringList" title="Link to this definition">¶</a><br /></dt>
  609. <dd><p>Set the list of wide strings <em>list</em> to <em>length</em> and <em>items</em>.</p>
  610. <p><a class="reference internal" href="#c-preinit"><span class="std std-ref">Preinitialize Python</span></a> if needed.</p>
  611. </dd></dl>
  612. <dl class="c function">
  613. <dt class="sig sig-object c" id="c.PyConfig_Read">
  614. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_Read</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_Read" title="Link to this definition">¶</a><br /></dt>
  615. <dd><p>Read all Python configuration.</p>
  616. <p>Fields which are already initialized are left unchanged.</p>
  617. <p>Fields for <a class="reference internal" href="#init-path-config"><span class="std std-ref">path configuration</span></a> are no longer
  618. calculated or modified when calling this function, as of Python 3.11.</p>
  619. <p>The <a class="reference internal" href="#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> function only parses
  620. <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a> arguments once: <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parse_argv</span></code></a>
  621. is set to <code class="docutils literal notranslate"><span class="pre">2</span></code> after arguments are parsed. Since Python arguments are
  622. strippped from <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a>, parsing arguments twice would
  623. parse the application options as Python options.</p>
  624. <p><a class="reference internal" href="#c-preinit"><span class="std std-ref">Preinitialize Python</span></a> if needed.</p>
  625. <div class="versionchanged">
  626. <p><span class="versionmodified changed">Changed in version 3.10: </span>The <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a> arguments are now only parsed once,
  627. <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parse_argv</span></code></a> is set to <code class="docutils literal notranslate"><span class="pre">2</span></code> after arguments are
  628. parsed, and arguments are only parsed if
  629. <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parse_argv</span></code></a> equals <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  630. </div>
  631. <div class="versionchanged">
  632. <p><span class="versionmodified changed">Changed in version 3.11: </span><a class="reference internal" href="#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> no longer calculates all paths, and so fields
  633. listed under <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> may
  634. no longer be updated until <a class="reference internal" href="#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> is
  635. called.</p>
  636. </div>
  637. </dd></dl>
  638. <dl class="c function">
  639. <dt class="sig sig-object c" id="c.PyConfig_Clear">
  640. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">PyConfig_Clear</span></span></span><span class="sig-paren">(</span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.PyConfig_Clear" title="Link to this definition">¶</a><br /></dt>
  641. <dd><p>Release configuration memory.</p>
  642. </dd></dl>
  643. <p>Most <code class="docutils literal notranslate"><span class="pre">PyConfig</span></code> methods <a class="reference internal" href="#c-preinit"><span class="std std-ref">preinitialize Python</span></a> if needed.
  644. In that case, the Python preinitialization configuration
  645. (<a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a>) in based on the <a class="reference internal" href="#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a>. If configuration
  646. fields which are in common with <a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a> are tuned, they must
  647. be set before calling a <a class="reference internal" href="#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> method:</p>
  648. <ul class="simple">
  649. <li><p><a class="reference internal" href="#c.PyConfig.dev_mode" title="PyConfig.dev_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.dev_mode</span></code></a></p></li>
  650. <li><p><a class="reference internal" href="#c.PyConfig.isolated" title="PyConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.isolated</span></code></a></p></li>
  651. <li><p><a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parse_argv</span></code></a></p></li>
  652. <li><p><a class="reference internal" href="#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.use_environment</span></code></a></p></li>
  653. </ul>
  654. <p>Moreover, if <a class="reference internal" href="#c.PyConfig_SetArgv" title="PyConfig_SetArgv"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetArgv()</span></code></a> or <a class="reference internal" href="#c.PyConfig_SetBytesArgv" title="PyConfig_SetBytesArgv"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_SetBytesArgv()</span></code></a>
  655. is used, this method must be called before other methods, since the
  656. preinitialization configuration depends on command line arguments (if
  657. <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">parse_argv</span></code></a> is non-zero).</p>
  658. <p>The caller of these methods is responsible to handle exceptions (error or
  659. exit) using <code class="docutils literal notranslate"><span class="pre">PyStatus_Exception()</span></code> and <code class="docutils literal notranslate"><span class="pre">Py_ExitStatusException()</span></code>.</p>
  660. <p>Structure fields:</p>
  661. <dl class="c member">
  662. <dt class="sig sig-object c" id="c.PyConfig.argv">
  663. <a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">argv</span></span></span><a class="headerlink" href="#c.PyConfig.argv" title="Link to this definition">¶</a><br /></dt>
  664. <dd><p>Command line arguments: <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a>.</p>
  665. <p>Set <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">parse_argv</span></code></a> to <code class="docutils literal notranslate"><span class="pre">1</span></code> to parse
  666. <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> the same way the regular Python parses Python
  667. command line arguments and then to strip Python arguments from
  668. <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a>.</p>
  669. <p>If <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> is empty, an empty string is added to
  670. ensure that <a class="reference internal" href="../library/sys.html#sys.argv" title="sys.argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.argv</span></code></a> always exists and is never empty.</p>
  671. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  672. <p>See also the <a class="reference internal" href="#c.PyConfig.orig_argv" title="PyConfig.orig_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">orig_argv</span></code></a> member.</p>
  673. </dd></dl>
  674. <dl class="c member">
  675. <dt class="sig sig-object c" id="c.PyConfig.safe_path">
  676. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">safe_path</span></span></span><a class="headerlink" href="#c.PyConfig.safe_path" title="Link to this definition">¶</a><br /></dt>
  677. <dd><p>If equals to zero, <code class="docutils literal notranslate"><span class="pre">Py_RunMain()</span></code> prepends a potentially unsafe path to
  678. <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> at startup:</p>
  679. <ul class="simple">
  680. <li><p>If <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv[0]</span></code></a> is equal to <code class="docutils literal notranslate"><span class="pre">L&quot;-m&quot;</span></code>
  681. (<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">module</span></code>), prepend the current working directory.</p></li>
  682. <li><p>If running a script (<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">script.py</span></code>), prepend the script’s
  683. directory. If it’s a symbolic link, resolve symbolic links.</p></li>
  684. <li><p>Otherwise (<code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-c</span> <span class="pre">code</span></code> and <code class="docutils literal notranslate"><span class="pre">python</span></code>), prepend an empty string,
  685. which means the current working directory.</p></li>
  686. </ul>
  687. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-P"><code class="xref std std-option docutils literal notranslate"><span class="pre">-P</span></code></a> command line option and the
  688. <span class="target" id="index-3"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONSAFEPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONSAFEPATH</span></code></a> environment variable.</p>
  689. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code> in Python config, <code class="docutils literal notranslate"><span class="pre">1</span></code> in isolated config.</p>
  690. <div class="versionadded">
  691. <p><span class="versionmodified added">New in version 3.11.</span></p>
  692. </div>
  693. </dd></dl>
  694. <dl class="c member">
  695. <dt class="sig sig-object c" id="c.PyConfig.base_exec_prefix">
  696. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">base_exec_prefix</span></span></span><a class="headerlink" href="#c.PyConfig.base_exec_prefix" title="Link to this definition">¶</a><br /></dt>
  697. <dd><p><a class="reference internal" href="../library/sys.html#sys.base_exec_prefix" title="sys.base_exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.base_exec_prefix</span></code></a>.</p>
  698. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  699. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> output.</p>
  700. </dd></dl>
  701. <dl class="c member">
  702. <dt class="sig sig-object c" id="c.PyConfig.base_executable">
  703. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">base_executable</span></span></span><a class="headerlink" href="#c.PyConfig.base_executable" title="Link to this definition">¶</a><br /></dt>
  704. <dd><p>Python base executable: <code class="xref py py-data docutils literal notranslate"><span class="pre">sys._base_executable</span></code>.</p>
  705. <p>Set by the <span class="target" id="index-4"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">__PYVENV_LAUNCHER__</span></code> environment variable.</p>
  706. <p>Set from <a class="reference internal" href="#c.PyConfig.executable" title="PyConfig.executable"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.executable</span></code></a> if <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  707. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  708. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> output.</p>
  709. </dd></dl>
  710. <dl class="c member">
  711. <dt class="sig sig-object c" id="c.PyConfig.base_prefix">
  712. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">base_prefix</span></span></span><a class="headerlink" href="#c.PyConfig.base_prefix" title="Link to this definition">¶</a><br /></dt>
  713. <dd><p><a class="reference internal" href="../library/sys.html#sys.base_prefix" title="sys.base_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.base_prefix</span></code></a>.</p>
  714. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  715. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> output.</p>
  716. </dd></dl>
  717. <dl class="c member">
  718. <dt class="sig sig-object c" id="c.PyConfig.buffered_stdio">
  719. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">buffered_stdio</span></span></span><a class="headerlink" href="#c.PyConfig.buffered_stdio" title="Link to this definition">¶</a><br /></dt>
  720. <dd><p>If equals to <code class="docutils literal notranslate"><span class="pre">0</span></code> and <a class="reference internal" href="#c.PyConfig.configure_c_stdio" title="PyConfig.configure_c_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">configure_c_stdio</span></code></a> is non-zero,
  721. disable buffering on the C streams stdout and stderr.</p>
  722. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-u"><code class="xref std std-option docutils literal notranslate"><span class="pre">-u</span></code></a> command line option and the
  723. <span class="target" id="index-5"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUNBUFFERED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUNBUFFERED</span></code></a> environment variable.</p>
  724. <p>stdin is always opened in buffered mode.</p>
  725. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  726. </dd></dl>
  727. <dl class="c member">
  728. <dt class="sig sig-object c" id="c.PyConfig.bytes_warning">
  729. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">bytes_warning</span></span></span><a class="headerlink" href="#c.PyConfig.bytes_warning" title="Link to this definition">¶</a><br /></dt>
  730. <dd><p>If equals to <code class="docutils literal notranslate"><span class="pre">1</span></code>, issue a warning when comparing <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> or
  731. <a class="reference internal" href="../library/stdtypes.html#bytearray" title="bytearray"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytearray</span></code></a> with <a class="reference internal" href="../library/stdtypes.html#str" title="str"><code class="xref py py-class docutils literal notranslate"><span class="pre">str</span></code></a>, or comparing <a class="reference internal" href="../library/stdtypes.html#bytes" title="bytes"><code class="xref py py-class docutils literal notranslate"><span class="pre">bytes</span></code></a> with
  732. <a class="reference internal" href="../library/functions.html#int" title="int"><code class="xref py py-class docutils literal notranslate"><span class="pre">int</span></code></a>.</p>
  733. <p>If equal or greater to <code class="docutils literal notranslate"><span class="pre">2</span></code>, raise a <a class="reference internal" href="../library/exceptions.html#BytesWarning" title="BytesWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">BytesWarning</span></code></a> exception in these
  734. cases.</p>
  735. <p>Incremented by the <a class="reference internal" href="../using/cmdline.html#cmdoption-b"><code class="xref std std-option docutils literal notranslate"><span class="pre">-b</span></code></a> command line option.</p>
  736. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  737. </dd></dl>
  738. <dl class="c member">
  739. <dt class="sig sig-object c" id="c.PyConfig.warn_default_encoding">
  740. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">warn_default_encoding</span></span></span><a class="headerlink" href="#c.PyConfig.warn_default_encoding" title="Link to this definition">¶</a><br /></dt>
  741. <dd><p>If non-zero, emit a <a class="reference internal" href="../library/exceptions.html#EncodingWarning" title="EncodingWarning"><code class="xref py py-exc docutils literal notranslate"><span class="pre">EncodingWarning</span></code></a> warning when <a class="reference internal" href="../library/io.html#io.TextIOWrapper" title="io.TextIOWrapper"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.TextIOWrapper</span></code></a>
  742. uses its default encoding. See <a class="reference internal" href="../library/io.html#io-encoding-warning"><span class="std std-ref">Opt-in EncodingWarning</span></a> for details.</p>
  743. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  744. <div class="versionadded">
  745. <p><span class="versionmodified added">New in version 3.10.</span></p>
  746. </div>
  747. </dd></dl>
  748. <dl class="c member">
  749. <dt class="sig sig-object c" id="c.PyConfig.code_debug_ranges">
  750. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">code_debug_ranges</span></span></span><a class="headerlink" href="#c.PyConfig.code_debug_ranges" title="Link to this definition">¶</a><br /></dt>
  751. <dd><p>If equals to <code class="docutils literal notranslate"><span class="pre">0</span></code>, disables the inclusion of the end line and column
  752. mappings in code objects. Also disables traceback printing carets to
  753. specific error locations.</p>
  754. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by the <span class="target" id="index-6"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONNODEBUGRANGES"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONNODEBUGRANGES</span></code></a> environment variable
  755. and by the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">no_debug_ranges</span></code></a> command line option.</p>
  756. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  757. <div class="versionadded">
  758. <p><span class="versionmodified added">New in version 3.11.</span></p>
  759. </div>
  760. </dd></dl>
  761. <dl class="c member">
  762. <dt class="sig sig-object c" id="c.PyConfig.check_hash_pycs_mode">
  763. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">check_hash_pycs_mode</span></span></span><a class="headerlink" href="#c.PyConfig.check_hash_pycs_mode" title="Link to this definition">¶</a><br /></dt>
  764. <dd><p>Control the validation behavior of hash-based <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files:
  765. value of the <a class="reference internal" href="../using/cmdline.html#cmdoption-check-hash-based-pycs"><code class="xref std std-option docutils literal notranslate"><span class="pre">--check-hash-based-pycs</span></code></a> command line option.</p>
  766. <p>Valid values:</p>
  767. <ul class="simple">
  768. <li><p><code class="docutils literal notranslate"><span class="pre">L&quot;always&quot;</span></code>: Hash the source file for invalidation regardless of
  769. value of the ‘check_source’ flag.</p></li>
  770. <li><p><code class="docutils literal notranslate"><span class="pre">L&quot;never&quot;</span></code>: Assume that hash-based pycs always are valid.</p></li>
  771. <li><p><code class="docutils literal notranslate"><span class="pre">L&quot;default&quot;</span></code>: The ‘check_source’ flag in hash-based pycs
  772. determines invalidation.</p></li>
  773. </ul>
  774. <p>Default: <code class="docutils literal notranslate"><span class="pre">L&quot;default&quot;</span></code>.</p>
  775. <p>See also <span class="target" id="index-7"></span><a class="pep reference external" href="https://peps.python.org/pep-0552/"><strong>PEP 552</strong></a> “Deterministic pycs”.</p>
  776. </dd></dl>
  777. <dl class="c member">
  778. <dt class="sig sig-object c" id="c.PyConfig.configure_c_stdio">
  779. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">configure_c_stdio</span></span></span><a class="headerlink" href="#c.PyConfig.configure_c_stdio" title="Link to this definition">¶</a><br /></dt>
  780. <dd><p>If non-zero, configure C standard streams:</p>
  781. <ul class="simple">
  782. <li><p>On Windows, set the binary mode (<code class="docutils literal notranslate"><span class="pre">O_BINARY</span></code>) on stdin, stdout and
  783. stderr.</p></li>
  784. <li><p>If <a class="reference internal" href="#c.PyConfig.buffered_stdio" title="PyConfig.buffered_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">buffered_stdio</span></code></a> equals zero, disable buffering
  785. of stdin, stdout and stderr streams.</p></li>
  786. <li><p>If <a class="reference internal" href="#c.PyConfig.interactive" title="PyConfig.interactive"><code class="xref c c-member docutils literal notranslate"><span class="pre">interactive</span></code></a> is non-zero, enable stream
  787. buffering on stdin and stdout (only stdout on Windows).</p></li>
  788. </ul>
  789. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python config, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  790. </dd></dl>
  791. <dl class="c member">
  792. <dt class="sig sig-object c" id="c.PyConfig.dev_mode">
  793. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">dev_mode</span></span></span><a class="headerlink" href="#c.PyConfig.dev_mode" title="Link to this definition">¶</a><br /></dt>
  794. <dd><p>If non-zero, enable the <a class="reference internal" href="../library/devmode.html#devmode"><span class="std std-ref">Python Development Mode</span></a>.</p>
  795. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">dev</span></code></a> option and the
  796. <span class="target" id="index-8"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDEVMODE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDEVMODE</span></code></a> environment variable.</p>
  797. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  798. </dd></dl>
  799. <dl class="c member">
  800. <dt class="sig sig-object c" id="c.PyConfig.dump_refs">
  801. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">dump_refs</span></span></span><a class="headerlink" href="#c.PyConfig.dump_refs" title="Link to this definition">¶</a><br /></dt>
  802. <dd><p>Dump Python references?</p>
  803. <p>If non-zero, dump all objects which are still alive at exit.</p>
  804. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <span class="target" id="index-9"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDUMPREFS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDUMPREFS</span></code></a> environment variable.</p>
  805. <p>Need a special build of Python with the <code class="docutils literal notranslate"><span class="pre">Py_TRACE_REFS</span></code> macro defined:
  806. see the <a class="reference internal" href="../using/configure.html#cmdoption-with-trace-refs"><code class="xref std std-option docutils literal notranslate"><span class="pre">configure</span> <span class="pre">--with-trace-refs</span> <span class="pre">option</span></code></a>.</p>
  807. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  808. </dd></dl>
  809. <dl class="c member">
  810. <dt class="sig sig-object c" id="c.PyConfig.exec_prefix">
  811. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">exec_prefix</span></span></span><a class="headerlink" href="#c.PyConfig.exec_prefix" title="Link to this definition">¶</a><br /></dt>
  812. <dd><p>The site-specific directory prefix where the platform-dependent Python
  813. files are installed: <a class="reference internal" href="../library/sys.html#sys.exec_prefix" title="sys.exec_prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.exec_prefix</span></code></a>.</p>
  814. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  815. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> output.</p>
  816. </dd></dl>
  817. <dl class="c member">
  818. <dt class="sig sig-object c" id="c.PyConfig.executable">
  819. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">executable</span></span></span><a class="headerlink" href="#c.PyConfig.executable" title="Link to this definition">¶</a><br /></dt>
  820. <dd><p>The absolute path of the executable binary for the Python interpreter:
  821. <a class="reference internal" href="../library/sys.html#sys.executable" title="sys.executable"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.executable</span></code></a>.</p>
  822. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  823. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> output.</p>
  824. </dd></dl>
  825. <dl class="c member">
  826. <dt class="sig sig-object c" id="c.PyConfig.faulthandler">
  827. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">faulthandler</span></span></span><a class="headerlink" href="#c.PyConfig.faulthandler" title="Link to this definition">¶</a><br /></dt>
  828. <dd><p>Enable faulthandler?</p>
  829. <p>If non-zero, call <a class="reference internal" href="../library/faulthandler.html#faulthandler.enable" title="faulthandler.enable"><code class="xref py py-func docutils literal notranslate"><span class="pre">faulthandler.enable()</span></code></a> at startup.</p>
  830. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">faulthandler</span></code></a> and the
  831. <span class="target" id="index-10"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONFAULTHANDLER"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONFAULTHANDLER</span></code></a> environment variable.</p>
  832. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  833. </dd></dl>
  834. <dl class="c member">
  835. <dt class="sig sig-object c" id="c.PyConfig.filesystem_encoding">
  836. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">filesystem_encoding</span></span></span><a class="headerlink" href="#c.PyConfig.filesystem_encoding" title="Link to this definition">¶</a><br /></dt>
  837. <dd><p><a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">Filesystem encoding</span></a>:
  838. <a class="reference internal" href="../library/sys.html#sys.getfilesystemencoding" title="sys.getfilesystemencoding"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencoding()</span></code></a>.</p>
  839. <p>On macOS, Android and VxWorks: use <code class="docutils literal notranslate"><span class="pre">&quot;utf-8&quot;</span></code> by default.</p>
  840. <p>On Windows: use <code class="docutils literal notranslate"><span class="pre">&quot;utf-8&quot;</span></code> by default, or <code class="docutils literal notranslate"><span class="pre">&quot;mbcs&quot;</span></code> if
  841. <a class="reference internal" href="#c.PyPreConfig.legacy_windows_fs_encoding" title="PyPreConfig.legacy_windows_fs_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">legacy_windows_fs_encoding</span></code></a> of
  842. <a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a> is non-zero.</p>
  843. <p>Default encoding on other platforms:</p>
  844. <ul class="simple">
  845. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;utf-8&quot;</span></code> if <a class="reference internal" href="#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a> is non-zero.</p></li>
  846. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;ascii&quot;</span></code> if Python detects that <code class="docutils literal notranslate"><span class="pre">nl_langinfo(CODESET)</span></code> announces
  847. the ASCII encoding, whereas the <code class="docutils literal notranslate"><span class="pre">mbstowcs()</span></code> function
  848. decodes from a different encoding (usually Latin1).</p></li>
  849. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;utf-8&quot;</span></code> if <code class="docutils literal notranslate"><span class="pre">nl_langinfo(CODESET)</span></code> returns an empty string.</p></li>
  850. <li><p>Otherwise, use the <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a>:
  851. <code class="docutils literal notranslate"><span class="pre">nl_langinfo(CODESET)</span></code> result.</p></li>
  852. </ul>
  853. <p>At Python startup, the encoding name is normalized to the Python codec
  854. name. For example, <code class="docutils literal notranslate"><span class="pre">&quot;ANSI_X3.4-1968&quot;</span></code> is replaced with <code class="docutils literal notranslate"><span class="pre">&quot;ascii&quot;</span></code>.</p>
  855. <p>See also the <a class="reference internal" href="#c.PyConfig.filesystem_errors" title="PyConfig.filesystem_errors"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_errors</span></code></a> member.</p>
  856. </dd></dl>
  857. <dl class="c member">
  858. <dt class="sig sig-object c" id="c.PyConfig.filesystem_errors">
  859. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">filesystem_errors</span></span></span><a class="headerlink" href="#c.PyConfig.filesystem_errors" title="Link to this definition">¶</a><br /></dt>
  860. <dd><p><a class="reference internal" href="../glossary.html#term-filesystem-encoding-and-error-handler"><span class="xref std std-term">Filesystem error handler</span></a>:
  861. <a class="reference internal" href="../library/sys.html#sys.getfilesystemencodeerrors" title="sys.getfilesystemencodeerrors"><code class="xref py py-func docutils literal notranslate"><span class="pre">sys.getfilesystemencodeerrors()</span></code></a>.</p>
  862. <p>On Windows: use <code class="docutils literal notranslate"><span class="pre">&quot;surrogatepass&quot;</span></code> by default, or <code class="docutils literal notranslate"><span class="pre">&quot;replace&quot;</span></code> if
  863. <a class="reference internal" href="#c.PyPreConfig.legacy_windows_fs_encoding" title="PyPreConfig.legacy_windows_fs_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">legacy_windows_fs_encoding</span></code></a> of
  864. <a class="reference internal" href="#c.PyPreConfig" title="PyPreConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyPreConfig</span></code></a> is non-zero.</p>
  865. <p>On other platforms: use <code class="docutils literal notranslate"><span class="pre">&quot;surrogateescape&quot;</span></code> by default.</p>
  866. <p>Supported error handlers:</p>
  867. <ul class="simple">
  868. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;strict&quot;</span></code></p></li>
  869. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;surrogateescape&quot;</span></code></p></li>
  870. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;surrogatepass&quot;</span></code> (only supported with the UTF-8 encoding)</p></li>
  871. </ul>
  872. <p>See also the <a class="reference internal" href="#c.PyConfig.filesystem_encoding" title="PyConfig.filesystem_encoding"><code class="xref c c-member docutils literal notranslate"><span class="pre">filesystem_encoding</span></code></a> member.</p>
  873. </dd></dl>
  874. <dl class="c member">
  875. <dt class="sig sig-object c" id="c.PyConfig.hash_seed">
  876. <span class="kt"><span class="pre">unsigned</span></span><span class="w"> </span><span class="kt"><span class="pre">long</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">hash_seed</span></span></span><a class="headerlink" href="#c.PyConfig.hash_seed" title="Link to this definition">¶</a><br /></dt>
  877. <dd></dd></dl>
  878. <dl class="c member">
  879. <dt class="sig sig-object c" id="c.PyConfig.use_hash_seed">
  880. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">use_hash_seed</span></span></span><a class="headerlink" href="#c.PyConfig.use_hash_seed" title="Link to this definition">¶</a><br /></dt>
  881. <dd><p>Randomized hash function seed.</p>
  882. <p>If <a class="reference internal" href="#c.PyConfig.use_hash_seed" title="PyConfig.use_hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">use_hash_seed</span></code></a> is zero, a seed is chosen randomly
  883. at Python startup, and <a class="reference internal" href="#c.PyConfig.hash_seed" title="PyConfig.hash_seed"><code class="xref c c-member docutils literal notranslate"><span class="pre">hash_seed</span></code></a> is ignored.</p>
  884. <p>Set by the <span class="target" id="index-11"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHASHSEED"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHASHSEED</span></code></a> environment variable.</p>
  885. <p>Default <em>use_hash_seed</em> value: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated
  886. mode.</p>
  887. </dd></dl>
  888. <dl class="c member">
  889. <dt class="sig sig-object c" id="c.PyConfig.home">
  890. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">home</span></span></span><a class="headerlink" href="#c.PyConfig.home" title="Link to this definition">¶</a><br /></dt>
  891. <dd><p>Python home directory.</p>
  892. <p>If <a class="reference internal" href="init.html#c.Py_SetPythonHome" title="Py_SetPythonHome"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetPythonHome()</span></code></a> has been called, use its argument if it is
  893. not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  894. <p>Set by the <span class="target" id="index-12"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONHOME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONHOME</span></code></a> environment variable.</p>
  895. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  896. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> input.</p>
  897. </dd></dl>
  898. <dl class="c member">
  899. <dt class="sig sig-object c" id="c.PyConfig.import_time">
  900. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">import_time</span></span></span><a class="headerlink" href="#c.PyConfig.import_time" title="Link to this definition">¶</a><br /></dt>
  901. <dd><p>If non-zero, profile import time.</p>
  902. <p>Set the <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">importtime</span></code></a> option and the
  903. <span class="target" id="index-13"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPROFILEIMPORTTIME"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPROFILEIMPORTTIME</span></code></a> environment variable.</p>
  904. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  905. </dd></dl>
  906. <dl class="c member">
  907. <dt class="sig sig-object c" id="c.PyConfig.inspect">
  908. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">inspect</span></span></span><a class="headerlink" href="#c.PyConfig.inspect" title="Link to this definition">¶</a><br /></dt>
  909. <dd><p>Enter interactive mode after executing a script or a command.</p>
  910. <p>If greater than <code class="docutils literal notranslate"><span class="pre">0</span></code>, enable inspect: when a script is passed as first
  911. argument or the -c option is used, enter interactive mode after executing
  912. the script or the command, even when <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a> does not appear to
  913. be a terminal.</p>
  914. <p>Incremented by the <a class="reference internal" href="../using/cmdline.html#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a> command line option. Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> if the
  915. <span class="target" id="index-14"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONINSPECT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONINSPECT</span></code></a> environment variable is non-empty.</p>
  916. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  917. </dd></dl>
  918. <dl class="c member">
  919. <dt class="sig sig-object c" id="c.PyConfig.install_signal_handlers">
  920. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">install_signal_handlers</span></span></span><a class="headerlink" href="#c.PyConfig.install_signal_handlers" title="Link to this definition">¶</a><br /></dt>
  921. <dd><p>Install Python signal handlers?</p>
  922. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  923. </dd></dl>
  924. <dl class="c member">
  925. <dt class="sig sig-object c" id="c.PyConfig.interactive">
  926. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">interactive</span></span></span><a class="headerlink" href="#c.PyConfig.interactive" title="Link to this definition">¶</a><br /></dt>
  927. <dd><p>If greater than <code class="docutils literal notranslate"><span class="pre">0</span></code>, enable the interactive mode (REPL).</p>
  928. <p>Incremented by the <a class="reference internal" href="../using/cmdline.html#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a> command line option.</p>
  929. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  930. </dd></dl>
  931. <dl class="c member">
  932. <dt class="sig sig-object c" id="c.PyConfig.int_max_str_digits">
  933. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">int_max_str_digits</span></span></span><a class="headerlink" href="#c.PyConfig.int_max_str_digits" title="Link to this definition">¶</a><br /></dt>
  934. <dd><p>Configures the <a class="reference internal" href="../library/stdtypes.html#int-max-str-digits"><span class="std std-ref">integer string conversion length limitation</span></a>. An initial value of <code class="docutils literal notranslate"><span class="pre">-1</span></code> means the value will
  935. be taken from the command line or environment or otherwise default to
  936. 4300 (<a class="reference internal" href="../library/sys.html#sys.int_info.default_max_str_digits" title="sys.int_info.default_max_str_digits"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.int_info.default_max_str_digits</span></code></a>). A value of <code class="docutils literal notranslate"><span class="pre">0</span></code>
  937. disables the limitation. Values greater than zero but less than 640
  938. (<a class="reference internal" href="../library/sys.html#sys.int_info.str_digits_check_threshold" title="sys.int_info.str_digits_check_threshold"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.int_info.str_digits_check_threshold</span></code></a>) are unsupported and
  939. will produce an error.</p>
  940. <p>Configured by the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">int_max_str_digits</span></code></a> command line
  941. flag or the <span class="target" id="index-15"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONINTMAXSTRDIGITS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONINTMAXSTRDIGITS</span></code></a> environment variable.</p>
  942. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python mode. 4300
  943. (<a class="reference internal" href="../library/sys.html#sys.int_info.default_max_str_digits" title="sys.int_info.default_max_str_digits"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.int_info.default_max_str_digits</span></code></a>) in isolated mode.</p>
  944. <div class="versionadded">
  945. <p><span class="versionmodified added">New in version 3.12.</span></p>
  946. </div>
  947. </dd></dl>
  948. <dl class="c member">
  949. <dt class="sig sig-object c" id="c.PyConfig.isolated">
  950. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">isolated</span></span></span><a class="headerlink" href="#c.PyConfig.isolated" title="Link to this definition">¶</a><br /></dt>
  951. <dd><p>If greater than <code class="docutils literal notranslate"><span class="pre">0</span></code>, enable isolated mode:</p>
  952. <ul class="simple">
  953. <li><p>Set <a class="reference internal" href="#c.PyConfig.safe_path" title="PyConfig.safe_path"><code class="xref c c-member docutils literal notranslate"><span class="pre">safe_path</span></code></a> to <code class="docutils literal notranslate"><span class="pre">1</span></code>:
  954. don’t prepend a potentially unsafe path to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> at Python
  955. startup, such as the current directory, the script’s directory or an
  956. empty string.</p></li>
  957. <li><p>Set <a class="reference internal" href="#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">use_environment</span></code></a> to <code class="docutils literal notranslate"><span class="pre">0</span></code>: ignore <code class="docutils literal notranslate"><span class="pre">PYTHON</span></code>
  958. environment variables.</p></li>
  959. <li><p>Set <a class="reference internal" href="#c.PyConfig.user_site_directory" title="PyConfig.user_site_directory"><code class="xref c c-member docutils literal notranslate"><span class="pre">user_site_directory</span></code></a> to <code class="docutils literal notranslate"><span class="pre">0</span></code>: don’t add the user
  960. site directory to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p></li>
  961. <li><p>Python REPL doesn’t import <a class="reference internal" href="../library/readline.html#module-readline" title="readline: GNU readline support for Python. (Unix)"><code class="xref py py-mod docutils literal notranslate"><span class="pre">readline</span></code></a> nor enable default readline
  962. configuration on interactive prompts.</p></li>
  963. </ul>
  964. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> command line option.</p>
  965. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">1</span></code> in isolated mode.</p>
  966. <p>See also the <a class="reference internal" href="#init-isolated-conf"><span class="std std-ref">Isolated Configuration</span></a> and
  967. <a class="reference internal" href="#c.PyPreConfig.isolated" title="PyPreConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.isolated</span></code></a>.</p>
  968. </dd></dl>
  969. <dl class="c member">
  970. <dt class="sig sig-object c" id="c.PyConfig.legacy_windows_stdio">
  971. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">legacy_windows_stdio</span></span></span><a class="headerlink" href="#c.PyConfig.legacy_windows_stdio" title="Link to this definition">¶</a><br /></dt>
  972. <dd><p>If non-zero, use <a class="reference internal" href="../library/io.html#io.FileIO" title="io.FileIO"><code class="xref py py-class docutils literal notranslate"><span class="pre">io.FileIO</span></code></a> instead of
  973. <code class="xref py py-class docutils literal notranslate"><span class="pre">io._WindowsConsoleIO</span></code> for <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a>
  974. and <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a>.</p>
  975. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> if the <span class="target" id="index-16"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONLEGACYWINDOWSSTDIO"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONLEGACYWINDOWSSTDIO</span></code></a> environment
  976. variable is set to a non-empty string.</p>
  977. <p>Only available on Windows. <code class="docutils literal notranslate"><span class="pre">#ifdef</span> <span class="pre">MS_WINDOWS</span></code> macro can be used for
  978. Windows specific code.</p>
  979. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  980. <p>See also the <span class="target" id="index-17"></span><a class="pep reference external" href="https://peps.python.org/pep-0528/"><strong>PEP 528</strong></a> (Change Windows console encoding to UTF-8).</p>
  981. </dd></dl>
  982. <dl class="c member">
  983. <dt class="sig sig-object c" id="c.PyConfig.malloc_stats">
  984. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">malloc_stats</span></span></span><a class="headerlink" href="#c.PyConfig.malloc_stats" title="Link to this definition">¶</a><br /></dt>
  985. <dd><p>If non-zero, dump statistics on <a class="reference internal" href="memory.html#pymalloc"><span class="std std-ref">Python pymalloc memory allocator</span></a> at exit.</p>
  986. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <span class="target" id="index-18"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONMALLOCSTATS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONMALLOCSTATS</span></code></a> environment variable.</p>
  987. <p>The option is ignored if Python is <a class="reference internal" href="../using/configure.html#cmdoption-without-pymalloc"><code class="xref std std-option docutils literal notranslate"><span class="pre">configured</span> <span class="pre">using</span>
  988. <span class="pre">the</span> <span class="pre">--without-pymalloc</span> <span class="pre">option</span></code></a>.</p>
  989. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  990. </dd></dl>
  991. <dl class="c member">
  992. <dt class="sig sig-object c" id="c.PyConfig.platlibdir">
  993. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">platlibdir</span></span></span><a class="headerlink" href="#c.PyConfig.platlibdir" title="Link to this definition">¶</a><br /></dt>
  994. <dd><p>Platform library directory name: <a class="reference internal" href="../library/sys.html#sys.platlibdir" title="sys.platlibdir"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.platlibdir</span></code></a>.</p>
  995. <p>Set by the <span class="target" id="index-19"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPLATLIBDIR"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPLATLIBDIR</span></code></a> environment variable.</p>
  996. <p>Default: value of the <code class="docutils literal notranslate"><span class="pre">PLATLIBDIR</span></code> macro which is set by the
  997. <a class="reference internal" href="../using/configure.html#cmdoption-with-platlibdir"><code class="xref std std-option docutils literal notranslate"><span class="pre">configure</span> <span class="pre">--with-platlibdir</span> <span class="pre">option</span></code></a>
  998. (default: <code class="docutils literal notranslate"><span class="pre">&quot;lib&quot;</span></code>, or <code class="docutils literal notranslate"><span class="pre">&quot;DLLs&quot;</span></code> on Windows).</p>
  999. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> input.</p>
  1000. <div class="versionadded">
  1001. <p><span class="versionmodified added">New in version 3.9.</span></p>
  1002. </div>
  1003. <div class="versionchanged">
  1004. <p><span class="versionmodified changed">Changed in version 3.11: </span>This macro is now used on Windows to locate the standard
  1005. library extension modules, typically under <code class="docutils literal notranslate"><span class="pre">DLLs</span></code>. However,
  1006. for compatibility, note that this value is ignored for any
  1007. non-standard layouts, including in-tree builds and virtual
  1008. environments.</p>
  1009. </div>
  1010. </dd></dl>
  1011. <dl class="c member">
  1012. <dt class="sig sig-object c" id="c.PyConfig.pythonpath_env">
  1013. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">pythonpath_env</span></span></span><a class="headerlink" href="#c.PyConfig.pythonpath_env" title="Link to this definition">¶</a><br /></dt>
  1014. <dd><p>Module search paths (<a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>) as a string separated by <code class="docutils literal notranslate"><span class="pre">DELIM</span></code>
  1015. (<a class="reference internal" href="../library/os.html#os.pathsep" title="os.pathsep"><code class="xref py py-data docutils literal notranslate"><span class="pre">os.pathsep</span></code></a>).</p>
  1016. <p>Set by the <span class="target" id="index-20"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPATH"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPATH</span></code></a> environment variable.</p>
  1017. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1018. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> input.</p>
  1019. </dd></dl>
  1020. <dl class="c member">
  1021. <dt class="sig sig-object c" id="c.PyConfig.module_search_paths">
  1022. <a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">module_search_paths</span></span></span><a class="headerlink" href="#c.PyConfig.module_search_paths" title="Link to this definition">¶</a><br /></dt>
  1023. <dd></dd></dl>
  1024. <dl class="c member">
  1025. <dt class="sig sig-object c" id="c.PyConfig.module_search_paths_set">
  1026. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">module_search_paths_set</span></span></span><a class="headerlink" href="#c.PyConfig.module_search_paths_set" title="Link to this definition">¶</a><br /></dt>
  1027. <dd><p>Module search paths: <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p>
  1028. <p>If <a class="reference internal" href="#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">module_search_paths_set</span></code></a> is equal to <code class="docutils literal notranslate"><span class="pre">0</span></code>,
  1029. <a class="reference internal" href="#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> will replace
  1030. <a class="reference internal" href="#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">module_search_paths</span></code></a> and sets
  1031. <a class="reference internal" href="#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">module_search_paths_set</span></code></a> to <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  1032. <p>Default: empty list (<code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code>) and <code class="docutils literal notranslate"><span class="pre">0</span></code>
  1033. (<code class="docutils literal notranslate"><span class="pre">module_search_paths_set</span></code>).</p>
  1034. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> output.</p>
  1035. </dd></dl>
  1036. <dl class="c member">
  1037. <dt class="sig sig-object c" id="c.PyConfig.optimization_level">
  1038. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">optimization_level</span></span></span><a class="headerlink" href="#c.PyConfig.optimization_level" title="Link to this definition">¶</a><br /></dt>
  1039. <dd><p>Compilation optimization level:</p>
  1040. <ul class="simple">
  1041. <li><p><code class="docutils literal notranslate"><span class="pre">0</span></code>: Peephole optimizer, set <code class="docutils literal notranslate"><span class="pre">__debug__</span></code> to <code class="docutils literal notranslate"><span class="pre">True</span></code>.</p></li>
  1042. <li><p><code class="docutils literal notranslate"><span class="pre">1</span></code>: Level 0, remove assertions, set <code class="docutils literal notranslate"><span class="pre">__debug__</span></code> to <code class="docutils literal notranslate"><span class="pre">False</span></code>.</p></li>
  1043. <li><p><code class="docutils literal notranslate"><span class="pre">2</span></code>: Level 1, strip docstrings.</p></li>
  1044. </ul>
  1045. <p>Incremented by the <a class="reference internal" href="../using/cmdline.html#cmdoption-O"><code class="xref std std-option docutils literal notranslate"><span class="pre">-O</span></code></a> command line option. Set to the
  1046. <span class="target" id="index-21"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONOPTIMIZE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONOPTIMIZE</span></code></a> environment variable value.</p>
  1047. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  1048. </dd></dl>
  1049. <dl class="c member">
  1050. <dt class="sig sig-object c" id="c.PyConfig.orig_argv">
  1051. <a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">orig_argv</span></span></span><a class="headerlink" href="#c.PyConfig.orig_argv" title="Link to this definition">¶</a><br /></dt>
  1052. <dd><p>The list of the original command line arguments passed to the Python
  1053. executable: <a class="reference internal" href="../library/sys.html#sys.orig_argv" title="sys.orig_argv"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.orig_argv</span></code></a>.</p>
  1054. <p>If <a class="reference internal" href="#c.PyConfig.orig_argv" title="PyConfig.orig_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">orig_argv</span></code></a> list is empty and
  1055. <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> is not a list only containing an empty
  1056. string, <a class="reference internal" href="#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> copies <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> into
  1057. <a class="reference internal" href="#c.PyConfig.orig_argv" title="PyConfig.orig_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">orig_argv</span></code></a> before modifying
  1058. <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> (if <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">parse_argv</span></code></a> is
  1059. non-zero).</p>
  1060. <p>See also the <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> member and the
  1061. <a class="reference internal" href="#c.Py_GetArgcArgv" title="Py_GetArgcArgv"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_GetArgcArgv()</span></code></a> function.</p>
  1062. <p>Default: empty list.</p>
  1063. <div class="versionadded">
  1064. <p><span class="versionmodified added">New in version 3.10.</span></p>
  1065. </div>
  1066. </dd></dl>
  1067. <dl class="c member">
  1068. <dt class="sig sig-object c" id="c.PyConfig.parse_argv">
  1069. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">parse_argv</span></span></span><a class="headerlink" href="#c.PyConfig.parse_argv" title="Link to this definition">¶</a><br /></dt>
  1070. <dd><p>Parse command line arguments?</p>
  1071. <p>If equals to <code class="docutils literal notranslate"><span class="pre">1</span></code>, parse <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> the same way the regular
  1072. Python parses <a class="reference internal" href="../using/cmdline.html#using-on-cmdline"><span class="std std-ref">command line arguments</span></a>, and strip
  1073. Python arguments from <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a>.</p>
  1074. <p>The <a class="reference internal" href="#c.PyConfig_Read" title="PyConfig_Read"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_Read()</span></code></a> function only parses
  1075. <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a> arguments once: <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parse_argv</span></code></a>
  1076. is set to <code class="docutils literal notranslate"><span class="pre">2</span></code> after arguments are parsed. Since Python arguments are
  1077. strippped from <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a>, parsing arguments twice would
  1078. parse the application options as Python options.</p>
  1079. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  1080. <div class="versionchanged">
  1081. <p><span class="versionmodified changed">Changed in version 3.10: </span>The <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a> arguments are now only parsed if
  1082. <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.parse_argv</span></code></a> equals to <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  1083. </div>
  1084. </dd></dl>
  1085. <dl class="c member">
  1086. <dt class="sig sig-object c" id="c.PyConfig.parser_debug">
  1087. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">parser_debug</span></span></span><a class="headerlink" href="#c.PyConfig.parser_debug" title="Link to this definition">¶</a><br /></dt>
  1088. <dd><p>Parser debug mode. If greater than <code class="docutils literal notranslate"><span class="pre">0</span></code>, turn on parser debugging output (for expert only, depending
  1089. on compilation options).</p>
  1090. <p>Incremented by the <a class="reference internal" href="../using/cmdline.html#cmdoption-d"><code class="xref std std-option docutils literal notranslate"><span class="pre">-d</span></code></a> command line option. Set to the
  1091. <span class="target" id="index-22"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDEBUG"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDEBUG</span></code></a> environment variable value.</p>
  1092. <p>Need a <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build of Python</span></a> (the <code class="docutils literal notranslate"><span class="pre">Py_DEBUG</span></code> macro
  1093. must be defined).</p>
  1094. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  1095. </dd></dl>
  1096. <dl class="c member">
  1097. <dt class="sig sig-object c" id="c.PyConfig.pathconfig_warnings">
  1098. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">pathconfig_warnings</span></span></span><a class="headerlink" href="#c.PyConfig.pathconfig_warnings" title="Link to this definition">¶</a><br /></dt>
  1099. <dd><p>If non-zero, calculation of path configuration is allowed to log
  1100. warnings into <code class="docutils literal notranslate"><span class="pre">stderr</span></code>. If equals to <code class="docutils literal notranslate"><span class="pre">0</span></code>, suppress these warnings.</p>
  1101. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  1102. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> input.</p>
  1103. <div class="versionchanged">
  1104. <p><span class="versionmodified changed">Changed in version 3.11: </span>Now also applies on Windows.</p>
  1105. </div>
  1106. </dd></dl>
  1107. <dl class="c member">
  1108. <dt class="sig sig-object c" id="c.PyConfig.prefix">
  1109. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">prefix</span></span></span><a class="headerlink" href="#c.PyConfig.prefix" title="Link to this definition">¶</a><br /></dt>
  1110. <dd><p>The site-specific directory prefix where the platform independent Python
  1111. files are installed: <a class="reference internal" href="../library/sys.html#sys.prefix" title="sys.prefix"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.prefix</span></code></a>.</p>
  1112. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1113. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> output.</p>
  1114. </dd></dl>
  1115. <dl class="c member">
  1116. <dt class="sig sig-object c" id="c.PyConfig.program_name">
  1117. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">program_name</span></span></span><a class="headerlink" href="#c.PyConfig.program_name" title="Link to this definition">¶</a><br /></dt>
  1118. <dd><p>Program name used to initialize <a class="reference internal" href="#c.PyConfig.executable" title="PyConfig.executable"><code class="xref c c-member docutils literal notranslate"><span class="pre">executable</span></code></a> and in
  1119. early error messages during Python initialization.</p>
  1120. <ul class="simple">
  1121. <li><p>If <code class="xref py py-func docutils literal notranslate"><span class="pre">Py_SetProgramName()</span></code> has been called, use its argument.</p></li>
  1122. <li><p>On macOS, use <span class="target" id="index-23"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONEXECUTABLE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONEXECUTABLE</span></code></a> environment variable if set.</p></li>
  1123. <li><p>If the <code class="docutils literal notranslate"><span class="pre">WITH_NEXT_FRAMEWORK</span></code> macro is defined, use
  1124. <span class="target" id="index-24"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">__PYVENV_LAUNCHER__</span></code> environment variable if set.</p></li>
  1125. <li><p>Use <code class="docutils literal notranslate"><span class="pre">argv[0]</span></code> of <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a> if available and
  1126. non-empty.</p></li>
  1127. <li><p>Otherwise, use <code class="docutils literal notranslate"><span class="pre">L&quot;python&quot;</span></code> on Windows, or <code class="docutils literal notranslate"><span class="pre">L&quot;python3&quot;</span></code> on other
  1128. platforms.</p></li>
  1129. </ul>
  1130. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1131. <p>Part of the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Python Path Configuration</span></a> input.</p>
  1132. </dd></dl>
  1133. <dl class="c member">
  1134. <dt class="sig sig-object c" id="c.PyConfig.pycache_prefix">
  1135. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">pycache_prefix</span></span></span><a class="headerlink" href="#c.PyConfig.pycache_prefix" title="Link to this definition">¶</a><br /></dt>
  1136. <dd><p>Directory where cached <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files are written:
  1137. <a class="reference internal" href="../library/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>.</p>
  1138. <p>Set by the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">pycache_prefix=PATH</span></code></a> command line option and
  1139. the <span class="target" id="index-25"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPYCACHEPREFIX"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPYCACHEPREFIX</span></code></a> environment variable.</p>
  1140. <p>If <code class="docutils literal notranslate"><span class="pre">NULL</span></code>, <a class="reference internal" href="../library/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> is set to <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>
  1141. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1142. </dd></dl>
  1143. <dl class="c member">
  1144. <dt class="sig sig-object c" id="c.PyConfig.quiet">
  1145. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">quiet</span></span></span><a class="headerlink" href="#c.PyConfig.quiet" title="Link to this definition">¶</a><br /></dt>
  1146. <dd><p>Quiet mode. If greater than <code class="docutils literal notranslate"><span class="pre">0</span></code>, don’t display the copyright and version at
  1147. Python startup in interactive mode.</p>
  1148. <p>Incremented by the <a class="reference internal" href="../using/cmdline.html#cmdoption-q"><code class="xref std std-option docutils literal notranslate"><span class="pre">-q</span></code></a> command line option.</p>
  1149. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  1150. </dd></dl>
  1151. <dl class="c member">
  1152. <dt class="sig sig-object c" id="c.PyConfig.run_command">
  1153. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">run_command</span></span></span><a class="headerlink" href="#c.PyConfig.run_command" title="Link to this definition">¶</a><br /></dt>
  1154. <dd><p>Value of the <a class="reference internal" href="../using/cmdline.html#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> command line option.</p>
  1155. <p>Used by <a class="reference internal" href="#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a>.</p>
  1156. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1157. </dd></dl>
  1158. <dl class="c member">
  1159. <dt class="sig sig-object c" id="c.PyConfig.run_filename">
  1160. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">run_filename</span></span></span><a class="headerlink" href="#c.PyConfig.run_filename" title="Link to this definition">¶</a><br /></dt>
  1161. <dd><p>Filename passed on the command line: trailing command line argument
  1162. without <a class="reference internal" href="../using/cmdline.html#cmdoption-c"><code class="xref std std-option docutils literal notranslate"><span class="pre">-c</span></code></a> or <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a>. It is used by the
  1163. <a class="reference internal" href="#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a> function.</p>
  1164. <p>For example, it is set to <code class="docutils literal notranslate"><span class="pre">script.py</span></code> by the <code class="docutils literal notranslate"><span class="pre">python3</span> <span class="pre">script.py</span> <span class="pre">arg</span></code>
  1165. command line.</p>
  1166. <p>See also the <a class="reference internal" href="#c.PyConfig.skip_source_first_line" title="PyConfig.skip_source_first_line"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.skip_source_first_line</span></code></a> option.</p>
  1167. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1168. </dd></dl>
  1169. <dl class="c member">
  1170. <dt class="sig sig-object c" id="c.PyConfig.run_module">
  1171. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">run_module</span></span></span><a class="headerlink" href="#c.PyConfig.run_module" title="Link to this definition">¶</a><br /></dt>
  1172. <dd><p>Value of the <a class="reference internal" href="../using/cmdline.html#cmdoption-m"><code class="xref std std-option docutils literal notranslate"><span class="pre">-m</span></code></a> command line option.</p>
  1173. <p>Used by <a class="reference internal" href="#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a>.</p>
  1174. <p>Default: <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1175. </dd></dl>
  1176. <dl class="c member">
  1177. <dt class="sig sig-object c" id="c.PyConfig.show_ref_count">
  1178. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">show_ref_count</span></span></span><a class="headerlink" href="#c.PyConfig.show_ref_count" title="Link to this definition">¶</a><br /></dt>
  1179. <dd><p>Show total reference count at exit (excluding immortal objects)?</p>
  1180. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">showrefcount</span></code></a> command line option.</p>
  1181. <p>Need a <a class="reference internal" href="../using/configure.html#debug-build"><span class="std std-ref">debug build of Python</span></a> (the <code class="docutils literal notranslate"><span class="pre">Py_REF_DEBUG</span></code>
  1182. macro must be defined).</p>
  1183. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  1184. </dd></dl>
  1185. <dl class="c member">
  1186. <dt class="sig sig-object c" id="c.PyConfig.site_import">
  1187. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">site_import</span></span></span><a class="headerlink" href="#c.PyConfig.site_import" title="Link to this definition">¶</a><br /></dt>
  1188. <dd><p>Import the <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module at startup?</p>
  1189. <p>If equal to zero, disable the import of the module site and the
  1190. site-dependent manipulations of <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> that it entails.</p>
  1191. <p>Also disable these manipulations if the <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module is explicitly
  1192. imported later (call <a class="reference internal" href="../library/site.html#site.main" title="site.main"><code class="xref py py-func docutils literal notranslate"><span class="pre">site.main()</span></code></a> if you want them to be triggered).</p>
  1193. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-S"><code class="xref std std-option docutils literal notranslate"><span class="pre">-S</span></code></a> command line option.</p>
  1194. <p><a class="reference internal" href="../library/sys.html#sys.flags" title="sys.flags"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.flags.no_site</span></code></a> is set to the inverted value of
  1195. <a class="reference internal" href="#c.PyConfig.site_import" title="PyConfig.site_import"><code class="xref c c-member docutils literal notranslate"><span class="pre">site_import</span></code></a>.</p>
  1196. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  1197. </dd></dl>
  1198. <dl class="c member">
  1199. <dt class="sig sig-object c" id="c.PyConfig.skip_source_first_line">
  1200. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">skip_source_first_line</span></span></span><a class="headerlink" href="#c.PyConfig.skip_source_first_line" title="Link to this definition">¶</a><br /></dt>
  1201. <dd><p>If non-zero, skip the first line of the <a class="reference internal" href="#c.PyConfig.run_filename" title="PyConfig.run_filename"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.run_filename</span></code></a>
  1202. source.</p>
  1203. <p>It allows the usage of non-Unix forms of <code class="docutils literal notranslate"><span class="pre">#!cmd</span></code>. This is intended for
  1204. a DOS specific hack only.</p>
  1205. <p>Set to <code class="docutils literal notranslate"><span class="pre">1</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-x"><code class="xref std std-option docutils literal notranslate"><span class="pre">-x</span></code></a> command line option.</p>
  1206. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  1207. </dd></dl>
  1208. <dl class="c member">
  1209. <dt class="sig sig-object c" id="c.PyConfig.stdio_encoding">
  1210. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">stdio_encoding</span></span></span><a class="headerlink" href="#c.PyConfig.stdio_encoding" title="Link to this definition">¶</a><br /></dt>
  1211. <dd></dd></dl>
  1212. <dl class="c member">
  1213. <dt class="sig sig-object c" id="c.PyConfig.stdio_errors">
  1214. <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="sig-name descname"><span class="n"><span class="pre">stdio_errors</span></span></span><a class="headerlink" href="#c.PyConfig.stdio_errors" title="Link to this definition">¶</a><br /></dt>
  1215. <dd><p>Encoding and encoding errors of <a class="reference internal" href="../library/sys.html#sys.stdin" title="sys.stdin"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdin</span></code></a>, <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a> and
  1216. <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> (but <a class="reference internal" href="../library/sys.html#sys.stderr" title="sys.stderr"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stderr</span></code></a> always uses
  1217. <code class="docutils literal notranslate"><span class="pre">&quot;backslashreplace&quot;</span></code> error handler).</p>
  1218. <p>If <a class="reference internal" href="init.html#c.Py_SetStandardStreamEncoding" title="Py_SetStandardStreamEncoding"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_SetStandardStreamEncoding()</span></code></a> has been called, use its
  1219. <em>error</em> and <em>errors</em> arguments if they are not <code class="docutils literal notranslate"><span class="pre">NULL</span></code>.</p>
  1220. <p>Use the <span class="target" id="index-26"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONIOENCODING"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONIOENCODING</span></code></a> environment variable if it is
  1221. non-empty.</p>
  1222. <p>Default encoding:</p>
  1223. <ul class="simple">
  1224. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;UTF-8&quot;</span></code> if <a class="reference internal" href="#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a> is non-zero.</p></li>
  1225. <li><p>Otherwise, use the <a class="reference internal" href="../glossary.html#term-locale-encoding"><span class="xref std std-term">locale encoding</span></a>.</p></li>
  1226. </ul>
  1227. <p>Default error handler:</p>
  1228. <ul class="simple">
  1229. <li><p>On Windows: use <code class="docutils literal notranslate"><span class="pre">&quot;surrogateescape&quot;</span></code>.</p></li>
  1230. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;surrogateescape&quot;</span></code> if <a class="reference internal" href="#c.PyPreConfig.utf8_mode" title="PyPreConfig.utf8_mode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyPreConfig.utf8_mode</span></code></a> is non-zero,
  1231. or if the LC_CTYPE locale is “C” or “POSIX”.</p></li>
  1232. <li><p><code class="docutils literal notranslate"><span class="pre">&quot;strict&quot;</span></code> otherwise.</p></li>
  1233. </ul>
  1234. </dd></dl>
  1235. <dl class="c member">
  1236. <dt class="sig sig-object c" id="c.PyConfig.tracemalloc">
  1237. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">tracemalloc</span></span></span><a class="headerlink" href="#c.PyConfig.tracemalloc" title="Link to this definition">¶</a><br /></dt>
  1238. <dd><p>Enable tracemalloc?</p>
  1239. <p>If non-zero, call <a class="reference internal" href="../library/tracemalloc.html#tracemalloc.start" title="tracemalloc.start"><code class="xref py py-func docutils literal notranslate"><span class="pre">tracemalloc.start()</span></code></a> at startup.</p>
  1240. <p>Set by <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">tracemalloc=N</span></code></a> command line option and by the
  1241. <span class="target" id="index-27"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONTRACEMALLOC"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONTRACEMALLOC</span></code></a> environment variable.</p>
  1242. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  1243. </dd></dl>
  1244. <dl class="c member">
  1245. <dt class="sig sig-object c" id="c.PyConfig.perf_profiling">
  1246. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">perf_profiling</span></span></span><a class="headerlink" href="#c.PyConfig.perf_profiling" title="Link to this definition">¶</a><br /></dt>
  1247. <dd><p>Enable compatibility mode with the perf profiler?</p>
  1248. <p>If non-zero, initialize the perf trampoline. See <a class="reference internal" href="../howto/perf_profiling.html#perf-profiling"><span class="std std-ref">Python support for the Linux perf profiler</span></a>
  1249. for more information.</p>
  1250. <p>Set by <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span> <span class="pre">perf</span></code></a> command line option and by the
  1251. <span class="target" id="index-28"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONPERFSUPPORT"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONPERFSUPPORT</span></code></a> environment variable.</p>
  1252. <p>Default: <code class="docutils literal notranslate"><span class="pre">-1</span></code>.</p>
  1253. <div class="versionadded">
  1254. <p><span class="versionmodified added">New in version 3.12.</span></p>
  1255. </div>
  1256. </dd></dl>
  1257. <dl class="c member">
  1258. <dt class="sig sig-object c" id="c.PyConfig.use_environment">
  1259. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">use_environment</span></span></span><a class="headerlink" href="#c.PyConfig.use_environment" title="Link to this definition">¶</a><br /></dt>
  1260. <dd><p>Use <a class="reference internal" href="../using/cmdline.html#using-on-envvars"><span class="std std-ref">environment variables</span></a>?</p>
  1261. <p>If equals to zero, ignore the <a class="reference internal" href="../using/cmdline.html#using-on-envvars"><span class="std std-ref">environment variables</span></a>.</p>
  1262. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-E"><code class="xref std std-option docutils literal notranslate"><span class="pre">-E</span></code></a> environment variable.</p>
  1263. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python config and <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated config.</p>
  1264. </dd></dl>
  1265. <dl class="c member">
  1266. <dt class="sig sig-object c" id="c.PyConfig.user_site_directory">
  1267. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">user_site_directory</span></span></span><a class="headerlink" href="#c.PyConfig.user_site_directory" title="Link to this definition">¶</a><br /></dt>
  1268. <dd><p>If non-zero, add the user site directory to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p>
  1269. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-s"><code class="xref std std-option docutils literal notranslate"><span class="pre">-s</span></code></a> and <a class="reference internal" href="../using/cmdline.html#cmdoption-I"><code class="xref std std-option docutils literal notranslate"><span class="pre">-I</span></code></a> command line options.</p>
  1270. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by the <span class="target" id="index-29"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONNOUSERSITE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONNOUSERSITE</span></code></a> environment variable.</p>
  1271. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code> in Python mode, <code class="docutils literal notranslate"><span class="pre">0</span></code> in isolated mode.</p>
  1272. </dd></dl>
  1273. <dl class="c member">
  1274. <dt class="sig sig-object c" id="c.PyConfig.verbose">
  1275. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">verbose</span></span></span><a class="headerlink" href="#c.PyConfig.verbose" title="Link to this definition">¶</a><br /></dt>
  1276. <dd><p>Verbose mode. If greater than <code class="docutils literal notranslate"><span class="pre">0</span></code>, print a message each time a module is
  1277. imported, showing the place (filename or built-in module) from which
  1278. it is loaded.</p>
  1279. <p>If greater than or equal to <code class="docutils literal notranslate"><span class="pre">2</span></code>, print a message for each file that is
  1280. checked for when searching for a module. Also provides information on
  1281. module cleanup at exit.</p>
  1282. <p>Incremented by the <a class="reference internal" href="../using/cmdline.html#cmdoption-v"><code class="xref std std-option docutils literal notranslate"><span class="pre">-v</span></code></a> command line option.</p>
  1283. <p>Set by the <span class="target" id="index-30"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONVERBOSE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONVERBOSE</span></code></a> environment variable value.</p>
  1284. <p>Default: <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p>
  1285. </dd></dl>
  1286. <dl class="c member">
  1287. <dt class="sig sig-object c" id="c.PyConfig.warnoptions">
  1288. <a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">warnoptions</span></span></span><a class="headerlink" href="#c.PyConfig.warnoptions" title="Link to this definition">¶</a><br /></dt>
  1289. <dd><p>Options of the <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module to build warnings filters, lowest
  1290. to highest priority: <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a>.</p>
  1291. <p>The <a class="reference internal" href="../library/warnings.html#module-warnings" title="warnings: Issue warning messages and control their disposition."><code class="xref py py-mod docutils literal notranslate"><span class="pre">warnings</span></code></a> module adds <a class="reference internal" href="../library/sys.html#sys.warnoptions" title="sys.warnoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.warnoptions</span></code></a> in the reverse
  1292. order: the last <a class="reference internal" href="#c.PyConfig.warnoptions" title="PyConfig.warnoptions"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.warnoptions</span></code></a> item becomes the first
  1293. item of <code class="xref py py-data docutils literal notranslate"><span class="pre">warnings.filters</span></code> which is checked first (highest
  1294. priority).</p>
  1295. <p>The <a class="reference internal" href="../using/cmdline.html#cmdoption-W"><code class="xref std std-option docutils literal notranslate"><span class="pre">-W</span></code></a> command line options adds its value to
  1296. <a class="reference internal" href="#c.PyConfig.warnoptions" title="PyConfig.warnoptions"><code class="xref c c-member docutils literal notranslate"><span class="pre">warnoptions</span></code></a>, it can be used multiple times.</p>
  1297. <p>The <span class="target" id="index-31"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONWARNINGS"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONWARNINGS</span></code></a> environment variable can also be used to add
  1298. warning options. Multiple options can be specified, separated by commas
  1299. (<code class="docutils literal notranslate"><span class="pre">,</span></code>).</p>
  1300. <p>Default: empty list.</p>
  1301. </dd></dl>
  1302. <dl class="c member">
  1303. <dt class="sig sig-object c" id="c.PyConfig.write_bytecode">
  1304. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">write_bytecode</span></span></span><a class="headerlink" href="#c.PyConfig.write_bytecode" title="Link to this definition">¶</a><br /></dt>
  1305. <dd><p>If equal to <code class="docutils literal notranslate"><span class="pre">0</span></code>, Python won’t try to write <code class="docutils literal notranslate"><span class="pre">.pyc</span></code> files on the import of
  1306. source modules.</p>
  1307. <p>Set to <code class="docutils literal notranslate"><span class="pre">0</span></code> by the <a class="reference internal" href="../using/cmdline.html#cmdoption-B"><code class="xref std std-option docutils literal notranslate"><span class="pre">-B</span></code></a> command line option and the
  1308. <span class="target" id="index-32"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONDONTWRITEBYTECODE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONDONTWRITEBYTECODE</span></code></a> environment variable.</p>
  1309. <p><a class="reference internal" href="../library/sys.html#sys.dont_write_bytecode" title="sys.dont_write_bytecode"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.dont_write_bytecode</span></code></a> is initialized to the inverted value of
  1310. <a class="reference internal" href="#c.PyConfig.write_bytecode" title="PyConfig.write_bytecode"><code class="xref c c-member docutils literal notranslate"><span class="pre">write_bytecode</span></code></a>.</p>
  1311. <p>Default: <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  1312. </dd></dl>
  1313. <dl class="c member">
  1314. <dt class="sig sig-object c" id="c.PyConfig.xoptions">
  1315. <a class="reference internal" href="#c.PyWideStringList" title="PyWideStringList"><span class="n"><span class="pre">PyWideStringList</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">xoptions</span></span></span><a class="headerlink" href="#c.PyConfig.xoptions" title="Link to this definition">¶</a><br /></dt>
  1316. <dd><p>Values of the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> command line options: <a class="reference internal" href="../library/sys.html#sys._xoptions" title="sys._xoptions"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys._xoptions</span></code></a>.</p>
  1317. <p>Default: empty list.</p>
  1318. </dd></dl>
  1319. </dd></dl>
  1320. <p>If <a class="reference internal" href="#c.PyConfig.parse_argv" title="PyConfig.parse_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">parse_argv</span></code></a> is non-zero, <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a>
  1321. arguments are parsed the same way the regular Python parses <a class="reference internal" href="../using/cmdline.html#using-on-cmdline"><span class="std std-ref">command line
  1322. arguments</span></a>, and Python arguments are stripped from
  1323. <a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">argv</span></code></a>.</p>
  1324. <p>The <a class="reference internal" href="#c.PyConfig.xoptions" title="PyConfig.xoptions"><code class="xref c c-member docutils literal notranslate"><span class="pre">xoptions</span></code></a> options are parsed to set other options: see
  1325. the <a class="reference internal" href="../using/cmdline.html#cmdoption-X"><code class="xref std std-option docutils literal notranslate"><span class="pre">-X</span></code></a> command line option.</p>
  1326. <div class="versionchanged">
  1327. <p><span class="versionmodified changed">Changed in version 3.9: </span>The <code class="docutils literal notranslate"><span class="pre">show_alloc_count</span></code> field has been removed.</p>
  1328. </div>
  1329. </section>
  1330. <section id="initialization-with-pyconfig">
  1331. <h2>Initialization with PyConfig<a class="headerlink" href="#initialization-with-pyconfig" title="Link to this heading">¶</a></h2>
  1332. <p>Function to initialize Python:</p>
  1333. <dl class="c function">
  1334. <dt class="sig sig-object c" id="c.Py_InitializeFromConfig">
  1335. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_InitializeFromConfig</span></span></span><span class="sig-paren">(</span><span class="k"><span class="pre">const</span></span><span class="w"> </span><a class="reference internal" href="#c.PyConfig" title="PyConfig"><span class="n"><span class="pre">PyConfig</span></span></a><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">config</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_InitializeFromConfig" title="Link to this definition">¶</a><br /></dt>
  1336. <dd><p>Initialize Python from <em>config</em> configuration.</p>
  1337. </dd></dl>
  1338. <p>The caller is responsible to handle exceptions (error or exit) using
  1339. <a class="reference internal" href="#c.PyStatus_Exception" title="PyStatus_Exception"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyStatus_Exception()</span></code></a> and <a class="reference internal" href="#c.Py_ExitStatusException" title="Py_ExitStatusException"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_ExitStatusException()</span></code></a>.</p>
  1340. <p>If <a class="reference internal" href="import.html#c.PyImport_FrozenModules" title="PyImport_FrozenModules"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_FrozenModules()</span></code></a>, <a class="reference internal" href="import.html#c.PyImport_AppendInittab" title="PyImport_AppendInittab"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_AppendInittab()</span></code></a> or
  1341. <a class="reference internal" href="import.html#c.PyImport_ExtendInittab" title="PyImport_ExtendInittab"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ExtendInittab()</span></code></a> are used, they must be set or called after
  1342. Python preinitialization and before the Python initialization. If Python is
  1343. initialized multiple times, <a class="reference internal" href="import.html#c.PyImport_AppendInittab" title="PyImport_AppendInittab"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_AppendInittab()</span></code></a> or
  1344. <a class="reference internal" href="import.html#c.PyImport_ExtendInittab" title="PyImport_ExtendInittab"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyImport_ExtendInittab()</span></code></a> must be called before each Python
  1345. initialization.</p>
  1346. <p>The current configuration (<code class="docutils literal notranslate"><span class="pre">PyConfig</span></code> type) is stored in
  1347. <code class="docutils literal notranslate"><span class="pre">PyInterpreterState.config</span></code>.</p>
  1348. <p>Example setting the program name:</p>
  1349. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">init_python</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
  1350. <span class="p">{</span>
  1351. <span class="w"> </span><span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="p">;</span>
  1352. <span class="w"> </span><span class="n">PyConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span>
  1353. <span class="w"> </span><span class="n">PyConfig_InitPythonConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1354. <span class="w"> </span><span class="cm">/* Set the program name. Implicitly preinitialize Python. */</span>
  1355. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyConfig_SetString</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">config</span><span class="p">.</span><span class="n">program_name</span><span class="p">,</span>
  1356. <span class="w"> </span><span class="sa">L</span><span class="s">&quot;/path/to/my_program&quot;</span><span class="p">);</span>
  1357. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1358. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">exception</span><span class="p">;</span>
  1359. <span class="w"> </span><span class="p">}</span>
  1360. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_InitializeFromConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1361. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1362. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">exception</span><span class="p">;</span>
  1363. <span class="w"> </span><span class="p">}</span>
  1364. <span class="w"> </span><span class="n">PyConfig_Clear</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1365. <span class="w"> </span><span class="k">return</span><span class="p">;</span>
  1366. <span class="nl">exception</span><span class="p">:</span>
  1367. <span class="w"> </span><span class="n">PyConfig_Clear</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1368. <span class="w"> </span><span class="n">Py_ExitStatusException</span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
  1369. <span class="p">}</span>
  1370. </pre></div>
  1371. </div>
  1372. <p>More complete example modifying the default configuration, read the
  1373. configuration, and then override some parameters. Note that since
  1374. 3.11, many parameters are not calculated until initialization, and
  1375. so values cannot be read from the configuration structure. Any values
  1376. set before initialize is called will be left unchanged by
  1377. initialization:</p>
  1378. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="n">PyStatus</span><span class="w"> </span><span class="nf">init_python</span><span class="p">(</span><span class="k">const</span><span class="w"> </span><span class="kt">char</span><span class="w"> </span><span class="o">*</span><span class="n">program_name</span><span class="p">)</span>
  1379. <span class="p">{</span>
  1380. <span class="w"> </span><span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="p">;</span>
  1381. <span class="w"> </span><span class="n">PyConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span>
  1382. <span class="w"> </span><span class="n">PyConfig_InitPythonConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1383. <span class="w"> </span><span class="cm">/* Set the program name before reading the configuration</span>
  1384. <span class="cm"> (decode byte string from the locale encoding).</span>
  1385. <span class="cm"> Implicitly preinitialize Python. */</span>
  1386. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyConfig_SetBytesString</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">config</span><span class="p">.</span><span class="n">program_name</span><span class="p">,</span>
  1387. <span class="w"> </span><span class="n">program_name</span><span class="p">);</span>
  1388. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1389. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">done</span><span class="p">;</span>
  1390. <span class="w"> </span><span class="p">}</span>
  1391. <span class="w"> </span><span class="cm">/* Read all configuration at once */</span>
  1392. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyConfig_Read</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1393. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1394. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">done</span><span class="p">;</span>
  1395. <span class="w"> </span><span class="p">}</span>
  1396. <span class="w"> </span><span class="cm">/* Specify sys.path explicitly */</span>
  1397. <span class="w"> </span><span class="cm">/* If you want to modify the default set of paths, finish</span>
  1398. <span class="cm"> initialization first and then use PySys_GetObject(&quot;path&quot;) */</span>
  1399. <span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">module_search_paths_set</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">1</span><span class="p">;</span>
  1400. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyWideStringList_Append</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">.</span><span class="n">module_search_paths</span><span class="p">,</span>
  1401. <span class="w"> </span><span class="sa">L</span><span class="s">&quot;/path/to/stdlib&quot;</span><span class="p">);</span>
  1402. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1403. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">done</span><span class="p">;</span>
  1404. <span class="w"> </span><span class="p">}</span>
  1405. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyWideStringList_Append</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">.</span><span class="n">module_search_paths</span><span class="p">,</span>
  1406. <span class="w"> </span><span class="sa">L</span><span class="s">&quot;/path/to/more/modules&quot;</span><span class="p">);</span>
  1407. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1408. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">done</span><span class="p">;</span>
  1409. <span class="w"> </span><span class="p">}</span>
  1410. <span class="w"> </span><span class="cm">/* Override executable computed by PyConfig_Read() */</span>
  1411. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyConfig_SetString</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">,</span><span class="w"> </span><span class="o">&amp;</span><span class="n">config</span><span class="p">.</span><span class="n">executable</span><span class="p">,</span>
  1412. <span class="w"> </span><span class="sa">L</span><span class="s">&quot;/path/to/my_executable&quot;</span><span class="p">);</span>
  1413. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1414. <span class="w"> </span><span class="k">goto</span><span class="w"> </span><span class="n">done</span><span class="p">;</span>
  1415. <span class="w"> </span><span class="p">}</span>
  1416. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_InitializeFromConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1417. <span class="nl">done</span><span class="p">:</span>
  1418. <span class="w"> </span><span class="n">PyConfig_Clear</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1419. <span class="w"> </span><span class="k">return</span><span class="w"> </span><span class="n">status</span><span class="p">;</span>
  1420. <span class="p">}</span>
  1421. </pre></div>
  1422. </div>
  1423. </section>
  1424. <section id="isolated-configuration">
  1425. <span id="init-isolated-conf"></span><h2>Isolated Configuration<a class="headerlink" href="#isolated-configuration" title="Link to this heading">¶</a></h2>
  1426. <p><a class="reference internal" href="#c.PyPreConfig_InitIsolatedConfig" title="PyPreConfig_InitIsolatedConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyPreConfig_InitIsolatedConfig()</span></code></a> and
  1427. <a class="reference internal" href="#c.PyConfig_InitIsolatedConfig" title="PyConfig_InitIsolatedConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_InitIsolatedConfig()</span></code></a> functions create a configuration to
  1428. isolate Python from the system. For example, to embed Python into an
  1429. application.</p>
  1430. <p>This configuration ignores global configuration variables, environment
  1431. variables, command line arguments (<a class="reference internal" href="#c.PyConfig.argv" title="PyConfig.argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.argv</span></code></a> is not parsed)
  1432. and user site directory. The C standard streams (ex: <code class="docutils literal notranslate"><span class="pre">stdout</span></code>) and the
  1433. LC_CTYPE locale are left unchanged. Signal handlers are not installed.</p>
  1434. <p>Configuration files are still used with this configuration to determine
  1435. paths that are unspecified. Ensure <a class="reference internal" href="#c.PyConfig.home" title="PyConfig.home"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.home</span></code></a> is specified
  1436. to avoid computing the default path configuration.</p>
  1437. </section>
  1438. <section id="python-configuration">
  1439. <span id="init-python-config"></span><h2>Python Configuration<a class="headerlink" href="#python-configuration" title="Link to this heading">¶</a></h2>
  1440. <p><a class="reference internal" href="#c.PyPreConfig_InitPythonConfig" title="PyPreConfig_InitPythonConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyPreConfig_InitPythonConfig()</span></code></a> and <a class="reference internal" href="#c.PyConfig_InitPythonConfig" title="PyConfig_InitPythonConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">PyConfig_InitPythonConfig()</span></code></a>
  1441. functions create a configuration to build a customized Python which behaves as
  1442. the regular Python.</p>
  1443. <p>Environments variables and command line arguments are used to configure
  1444. Python, whereas global configuration variables are ignored.</p>
  1445. <p>This function enables C locale coercion (<span class="target" id="index-33"></span><a class="pep reference external" href="https://peps.python.org/pep-0538/"><strong>PEP 538</strong></a>)
  1446. and <a class="reference internal" href="../library/os.html#utf8-mode"><span class="std std-ref">Python UTF-8 Mode</span></a>
  1447. (<span class="target" id="index-34"></span><a class="pep reference external" href="https://peps.python.org/pep-0540/"><strong>PEP 540</strong></a>) depending on the LC_CTYPE locale, <span class="target" id="index-35"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONUTF8"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONUTF8</span></code></a> and
  1448. <span class="target" id="index-36"></span><a class="reference internal" href="../using/cmdline.html#envvar-PYTHONCOERCECLOCALE"><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PYTHONCOERCECLOCALE</span></code></a> environment variables.</p>
  1449. </section>
  1450. <section id="python-path-configuration">
  1451. <span id="init-path-config"></span><h2>Python Path Configuration<a class="headerlink" href="#python-path-configuration" title="Link to this heading">¶</a></h2>
  1452. <p><a class="reference internal" href="#c.PyConfig" title="PyConfig"><code class="xref c c-type docutils literal notranslate"><span class="pre">PyConfig</span></code></a> contains multiple fields for the path configuration:</p>
  1453. <ul class="simple">
  1454. <li><p>Path configuration inputs:</p>
  1455. <ul>
  1456. <li><p><a class="reference internal" href="#c.PyConfig.home" title="PyConfig.home"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.home</span></code></a></p></li>
  1457. <li><p><a class="reference internal" href="#c.PyConfig.platlibdir" title="PyConfig.platlibdir"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.platlibdir</span></code></a></p></li>
  1458. <li><p><a class="reference internal" href="#c.PyConfig.pathconfig_warnings" title="PyConfig.pathconfig_warnings"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.pathconfig_warnings</span></code></a></p></li>
  1459. <li><p><a class="reference internal" href="#c.PyConfig.program_name" title="PyConfig.program_name"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.program_name</span></code></a></p></li>
  1460. <li><p><a class="reference internal" href="#c.PyConfig.pythonpath_env" title="PyConfig.pythonpath_env"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.pythonpath_env</span></code></a></p></li>
  1461. <li><p>current working directory: to get absolute paths</p></li>
  1462. <li><p><code class="docutils literal notranslate"><span class="pre">PATH</span></code> environment variable to get the program full path
  1463. (from <a class="reference internal" href="#c.PyConfig.program_name" title="PyConfig.program_name"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.program_name</span></code></a>)</p></li>
  1464. <li><p><code class="docutils literal notranslate"><span class="pre">__PYVENV_LAUNCHER__</span></code> environment variable</p></li>
  1465. <li><p>(Windows only) Application paths in the registry under
  1466. “SoftwarePythonPythonCoreX.YPythonPath” of HKEY_CURRENT_USER and
  1467. HKEY_LOCAL_MACHINE (where X.Y is the Python version).</p></li>
  1468. </ul>
  1469. </li>
  1470. <li><p>Path configuration output fields:</p>
  1471. <ul>
  1472. <li><p><a class="reference internal" href="#c.PyConfig.base_exec_prefix" title="PyConfig.base_exec_prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.base_exec_prefix</span></code></a></p></li>
  1473. <li><p><a class="reference internal" href="#c.PyConfig.base_executable" title="PyConfig.base_executable"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.base_executable</span></code></a></p></li>
  1474. <li><p><a class="reference internal" href="#c.PyConfig.base_prefix" title="PyConfig.base_prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.base_prefix</span></code></a></p></li>
  1475. <li><p><a class="reference internal" href="#c.PyConfig.exec_prefix" title="PyConfig.exec_prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.exec_prefix</span></code></a></p></li>
  1476. <li><p><a class="reference internal" href="#c.PyConfig.executable" title="PyConfig.executable"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.executable</span></code></a></p></li>
  1477. <li><p><a class="reference internal" href="#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths_set</span></code></a>,
  1478. <a class="reference internal" href="#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.module_search_paths</span></code></a></p></li>
  1479. <li><p><a class="reference internal" href="#c.PyConfig.prefix" title="PyConfig.prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.prefix</span></code></a></p></li>
  1480. </ul>
  1481. </li>
  1482. </ul>
  1483. <p>If at least one “output field” is not set, Python calculates the path
  1484. configuration to fill unset fields. If
  1485. <a class="reference internal" href="#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">module_search_paths_set</span></code></a> is equal to <code class="docutils literal notranslate"><span class="pre">0</span></code>,
  1486. <a class="reference internal" href="#c.PyConfig.module_search_paths" title="PyConfig.module_search_paths"><code class="xref c c-member docutils literal notranslate"><span class="pre">module_search_paths</span></code></a> is overridden and
  1487. <a class="reference internal" href="#c.PyConfig.module_search_paths_set" title="PyConfig.module_search_paths_set"><code class="xref c c-member docutils literal notranslate"><span class="pre">module_search_paths_set</span></code></a> is set to <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p>
  1488. <p>It is possible to completely ignore the function calculating the default
  1489. path configuration by setting explicitly all path configuration output
  1490. fields listed above. A string is considered as set even if it is non-empty.
  1491. <code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code> is considered as set if
  1492. <code class="docutils literal notranslate"><span class="pre">module_search_paths_set</span></code> is set to <code class="docutils literal notranslate"><span class="pre">1</span></code>. In this case,
  1493. <code class="docutils literal notranslate"><span class="pre">module_search_paths</span></code> will be used without modification.</p>
  1494. <p>Set <a class="reference internal" href="#c.PyConfig.pathconfig_warnings" title="PyConfig.pathconfig_warnings"><code class="xref c c-member docutils literal notranslate"><span class="pre">pathconfig_warnings</span></code></a> to <code class="docutils literal notranslate"><span class="pre">0</span></code> to suppress warnings when
  1495. calculating the path configuration (Unix only, Windows does not log any warning).</p>
  1496. <p>If <a class="reference internal" href="#c.PyConfig.base_prefix" title="PyConfig.base_prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">base_prefix</span></code></a> or <a class="reference internal" href="#c.PyConfig.base_exec_prefix" title="PyConfig.base_exec_prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">base_exec_prefix</span></code></a>
  1497. fields are not set, they inherit their value from <a class="reference internal" href="#c.PyConfig.prefix" title="PyConfig.prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">prefix</span></code></a>
  1498. and <a class="reference internal" href="#c.PyConfig.exec_prefix" title="PyConfig.exec_prefix"><code class="xref c c-member docutils literal notranslate"><span class="pre">exec_prefix</span></code></a> respectively.</p>
  1499. <p><a class="reference internal" href="#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a> and <a class="reference internal" href="veryhigh.html#c.Py_Main" title="Py_Main"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_Main()</span></code></a> modify <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>:</p>
  1500. <ul class="simple">
  1501. <li><p>If <a class="reference internal" href="#c.PyConfig.run_filename" title="PyConfig.run_filename"><code class="xref c c-member docutils literal notranslate"><span class="pre">run_filename</span></code></a> is set and is a directory which contains a
  1502. <code class="docutils literal notranslate"><span class="pre">__main__.py</span></code> script, prepend <a class="reference internal" href="#c.PyConfig.run_filename" title="PyConfig.run_filename"><code class="xref c c-member docutils literal notranslate"><span class="pre">run_filename</span></code></a> to
  1503. <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p></li>
  1504. <li><p>If <a class="reference internal" href="#c.PyConfig.isolated" title="PyConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">isolated</span></code></a> is zero:</p>
  1505. <ul>
  1506. <li><p>If <a class="reference internal" href="#c.PyConfig.run_module" title="PyConfig.run_module"><code class="xref c c-member docutils literal notranslate"><span class="pre">run_module</span></code></a> is set, prepend the current directory
  1507. to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>. Do nothing if the current directory cannot be read.</p></li>
  1508. <li><p>If <a class="reference internal" href="#c.PyConfig.run_filename" title="PyConfig.run_filename"><code class="xref c c-member docutils literal notranslate"><span class="pre">run_filename</span></code></a> is set, prepend the directory of the
  1509. filename to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p></li>
  1510. <li><p>Otherwise, prepend an empty string to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p></li>
  1511. </ul>
  1512. </li>
  1513. </ul>
  1514. <p>If <a class="reference internal" href="#c.PyConfig.site_import" title="PyConfig.site_import"><code class="xref c c-member docutils literal notranslate"><span class="pre">site_import</span></code></a> is non-zero, <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> can be
  1515. modified by the <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module. If
  1516. <a class="reference internal" href="#c.PyConfig.user_site_directory" title="PyConfig.user_site_directory"><code class="xref c c-member docutils literal notranslate"><span class="pre">user_site_directory</span></code></a> is non-zero and the user’s
  1517. site-package directory exists, the <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module appends the user’s
  1518. site-package directory to <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>.</p>
  1519. <p>The following configuration files are used by the path configuration:</p>
  1520. <ul class="simple">
  1521. <li><p><code class="docutils literal notranslate"><span class="pre">pyvenv.cfg</span></code></p></li>
  1522. <li><p><code class="docutils literal notranslate"><span class="pre">._pth</span></code> file (ex: <code class="docutils literal notranslate"><span class="pre">python._pth</span></code>)</p></li>
  1523. <li><p><code class="docutils literal notranslate"><span class="pre">pybuilddir.txt</span></code> (Unix only)</p></li>
  1524. </ul>
  1525. <p>If a <code class="docutils literal notranslate"><span class="pre">._pth</span></code> file is present:</p>
  1526. <ul class="simple">
  1527. <li><p>Set <a class="reference internal" href="#c.PyConfig.isolated" title="PyConfig.isolated"><code class="xref c c-member docutils literal notranslate"><span class="pre">isolated</span></code></a> to <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p></li>
  1528. <li><p>Set <a class="reference internal" href="#c.PyConfig.use_environment" title="PyConfig.use_environment"><code class="xref c c-member docutils literal notranslate"><span class="pre">use_environment</span></code></a> to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p></li>
  1529. <li><p>Set <a class="reference internal" href="#c.PyConfig.site_import" title="PyConfig.site_import"><code class="xref c c-member docutils literal notranslate"><span class="pre">site_import</span></code></a> to <code class="docutils literal notranslate"><span class="pre">0</span></code>.</p></li>
  1530. <li><p>Set <a class="reference internal" href="#c.PyConfig.safe_path" title="PyConfig.safe_path"><code class="xref c c-member docutils literal notranslate"><span class="pre">safe_path</span></code></a> to <code class="docutils literal notranslate"><span class="pre">1</span></code>.</p></li>
  1531. </ul>
  1532. <p>The <code class="docutils literal notranslate"><span class="pre">__PYVENV_LAUNCHER__</span></code> environment variable is used to set
  1533. <a class="reference internal" href="#c.PyConfig.base_executable" title="PyConfig.base_executable"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.base_executable</span></code></a></p>
  1534. </section>
  1535. <section id="py-runmain">
  1536. <h2>Py_RunMain()<a class="headerlink" href="#py-runmain" title="Link to this heading">¶</a></h2>
  1537. <dl class="c function">
  1538. <dt class="sig sig-object c" id="c.Py_RunMain">
  1539. <span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_RunMain</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_RunMain" title="Link to this definition">¶</a><br /></dt>
  1540. <dd><p>Execute the command (<a class="reference internal" href="#c.PyConfig.run_command" title="PyConfig.run_command"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.run_command</span></code></a>), the script
  1541. (<a class="reference internal" href="#c.PyConfig.run_filename" title="PyConfig.run_filename"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.run_filename</span></code></a>) or the module
  1542. (<a class="reference internal" href="#c.PyConfig.run_module" title="PyConfig.run_module"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.run_module</span></code></a>) specified on the command line or in the
  1543. configuration.</p>
  1544. <p>By default and when if <a class="reference internal" href="../using/cmdline.html#cmdoption-i"><code class="xref std std-option docutils literal notranslate"><span class="pre">-i</span></code></a> option is used, run the REPL.</p>
  1545. <p>Finally, finalizes Python and returns an exit status that can be passed to
  1546. the <code class="docutils literal notranslate"><span class="pre">exit()</span></code> function.</p>
  1547. </dd></dl>
  1548. <p>See <a class="reference internal" href="#init-python-config"><span class="std std-ref">Python Configuration</span></a> for an example of
  1549. customized Python always running in isolated mode using
  1550. <a class="reference internal" href="#c.Py_RunMain" title="Py_RunMain"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_RunMain()</span></code></a>.</p>
  1551. </section>
  1552. <section id="py-getargcargv">
  1553. <h2>Py_GetArgcArgv()<a class="headerlink" href="#py-getargcargv" title="Link to this heading">¶</a></h2>
  1554. <dl class="c function">
  1555. <dt class="sig sig-object c" id="c.Py_GetArgcArgv">
  1556. <span class="kt"><span class="pre">void</span></span><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">Py_GetArgcArgv</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">int</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argc</span></span>, <span class="n"><span class="pre">wchar_t</span></span><span class="w"> </span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="p"><span class="pre">*</span></span><span class="n"><span class="pre">argv</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c.Py_GetArgcArgv" title="Link to this definition">¶</a><br /></dt>
  1557. <dd><p>Get the original command line arguments, before Python modified them.</p>
  1558. <p>See also <a class="reference internal" href="#c.PyConfig.orig_argv" title="PyConfig.orig_argv"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.orig_argv</span></code></a> member.</p>
  1559. </dd></dl>
  1560. </section>
  1561. <section id="multi-phase-initialization-private-provisional-api">
  1562. <h2>Multi-Phase Initialization Private Provisional API<a class="headerlink" href="#multi-phase-initialization-private-provisional-api" title="Link to this heading">¶</a></h2>
  1563. <p>This section is a private provisional API introducing multi-phase
  1564. initialization, the core feature of <span class="target" id="index-37"></span><a class="pep reference external" href="https://peps.python.org/pep-0432/"><strong>PEP 432</strong></a>:</p>
  1565. <ul class="simple">
  1566. <li><p>“Core” initialization phase, “bare minimum Python”:</p>
  1567. <ul>
  1568. <li><p>Builtin types;</p></li>
  1569. <li><p>Builtin exceptions;</p></li>
  1570. <li><p>Builtin and frozen modules;</p></li>
  1571. <li><p>The <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> module is only partially initialized
  1572. (ex: <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a> doesn’t exist yet).</p></li>
  1573. </ul>
  1574. </li>
  1575. <li><p>“Main” initialization phase, Python is fully initialized:</p>
  1576. <ul>
  1577. <li><p>Install and configure <a class="reference internal" href="../library/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>;</p></li>
  1578. <li><p>Apply the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Path Configuration</span></a>;</p></li>
  1579. <li><p>Install signal handlers;</p></li>
  1580. <li><p>Finish <a class="reference internal" href="../library/sys.html#module-sys" title="sys: Access system-specific parameters and functions."><code class="xref py py-mod docutils literal notranslate"><span class="pre">sys</span></code></a> module initialization (ex: create <a class="reference internal" href="../library/sys.html#sys.stdout" title="sys.stdout"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.stdout</span></code></a>
  1581. and <a class="reference internal" href="../library/sys.html#sys.path" title="sys.path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.path</span></code></a>);</p></li>
  1582. <li><p>Enable optional features like <a class="reference internal" href="../library/faulthandler.html#module-faulthandler" title="faulthandler: Dump the Python traceback."><code class="xref py py-mod docutils literal notranslate"><span class="pre">faulthandler</span></code></a> and <a class="reference internal" href="../library/tracemalloc.html#module-tracemalloc" title="tracemalloc: Trace memory allocations."><code class="xref py py-mod docutils literal notranslate"><span class="pre">tracemalloc</span></code></a>;</p></li>
  1583. <li><p>Import the <a class="reference internal" href="../library/site.html#module-site" title="site: Module responsible for site-specific configuration."><code class="xref py py-mod docutils literal notranslate"><span class="pre">site</span></code></a> module;</p></li>
  1584. <li><p>etc.</p></li>
  1585. </ul>
  1586. </li>
  1587. </ul>
  1588. <p>Private provisional API:</p>
  1589. <ul class="simple">
  1590. <li><p><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig._init_main</span></code>: if set to <code class="docutils literal notranslate"><span class="pre">0</span></code>,
  1591. <a class="reference internal" href="#c.Py_InitializeFromConfig" title="Py_InitializeFromConfig"><code class="xref c c-func docutils literal notranslate"><span class="pre">Py_InitializeFromConfig()</span></code></a> stops at the “Core” initialization phase.</p></li>
  1592. </ul>
  1593. <dl class="c function">
  1594. <dt class="sig sig-object c" id="c._Py_InitializeMain">
  1595. <a class="reference internal" href="#c.PyStatus" title="PyStatus"><span class="n"><span class="pre">PyStatus</span></span></a><span class="w"> </span><span class="sig-name descname"><span class="n"><span class="pre">_Py_InitializeMain</span></span></span><span class="sig-paren">(</span><span class="kt"><span class="pre">void</span></span><span class="sig-paren">)</span><a class="headerlink" href="#c._Py_InitializeMain" title="Link to this definition">¶</a><br /></dt>
  1596. <dd><p>Move to the “Main” initialization phase, finish the Python initialization.</p>
  1597. </dd></dl>
  1598. <p>No module is imported during the “Core” phase and the <code class="docutils literal notranslate"><span class="pre">importlib</span></code> module is
  1599. not configured: the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Path Configuration</span></a> is only
  1600. applied during the “Main” phase. It may allow to customize Python in Python to
  1601. override or tune the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Path Configuration</span></a>, maybe
  1602. install a custom <a class="reference internal" href="../library/sys.html#sys.meta_path" title="sys.meta_path"><code class="xref py py-data docutils literal notranslate"><span class="pre">sys.meta_path</span></code></a> importer or an import hook, etc.</p>
  1603. <p>It may become possible to calculate the <a class="reference internal" href="#init-path-config"><span class="std std-ref">Path Configuration</span></a> in Python, after the Core phase and before the Main phase,
  1604. which is one of the <span class="target" id="index-38"></span><a class="pep reference external" href="https://peps.python.org/pep-0432/"><strong>PEP 432</strong></a> motivation.</p>
  1605. <p>The “Core” phase is not properly defined: what should be and what should
  1606. not be available at this phase is not specified yet. The API is marked
  1607. as private and provisional: the API can be modified or even be removed
  1608. anytime until a proper public API is designed.</p>
  1609. <p>Example running Python code between “Core” and “Main” initialization
  1610. phases:</p>
  1611. <div class="highlight-c notranslate"><div class="highlight"><pre><span></span><span class="kt">void</span><span class="w"> </span><span class="nf">init_python</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
  1612. <span class="p">{</span>
  1613. <span class="w"> </span><span class="n">PyStatus</span><span class="w"> </span><span class="n">status</span><span class="p">;</span>
  1614. <span class="w"> </span><span class="n">PyConfig</span><span class="w"> </span><span class="n">config</span><span class="p">;</span>
  1615. <span class="w"> </span><span class="n">PyConfig_InitPythonConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1616. <span class="w"> </span><span class="n">config</span><span class="p">.</span><span class="n">_init_main</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="mi">0</span><span class="p">;</span>
  1617. <span class="w"> </span><span class="cm">/* ... customize &#39;config&#39; configuration ... */</span>
  1618. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">Py_InitializeFromConfig</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1619. <span class="w"> </span><span class="n">PyConfig_Clear</span><span class="p">(</span><span class="o">&amp;</span><span class="n">config</span><span class="p">);</span>
  1620. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1621. <span class="w"> </span><span class="n">Py_ExitStatusException</span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
  1622. <span class="w"> </span><span class="p">}</span>
  1623. <span class="w"> </span><span class="cm">/* Use sys.stderr because sys.stdout is only created</span>
  1624. <span class="cm"> by _Py_InitializeMain() */</span>
  1625. <span class="w"> </span><span class="kt">int</span><span class="w"> </span><span class="n">res</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">PyRun_SimpleString</span><span class="p">(</span>
  1626. <span class="w"> </span><span class="s">&quot;import sys; &quot;</span>
  1627. <span class="w"> </span><span class="s">&quot;print(&#39;Run Python code before _Py_InitializeMain&#39;, &quot;</span>
  1628. <span class="w"> </span><span class="s">&quot;file=sys.stderr)&quot;</span><span class="p">);</span>
  1629. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">res</span><span class="w"> </span><span class="o">&lt;</span><span class="w"> </span><span class="mi">0</span><span class="p">)</span><span class="w"> </span><span class="p">{</span>
  1630. <span class="w"> </span><span class="n">exit</span><span class="p">(</span><span class="mi">1</span><span class="p">);</span>
  1631. <span class="w"> </span><span class="p">}</span>
  1632. <span class="w"> </span><span class="cm">/* ... put more configuration code here ... */</span>
  1633. <span class="w"> </span><span class="n">status</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">_Py_InitializeMain</span><span class="p">();</span>
  1634. <span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="p">(</span><span class="n">PyStatus_Exception</span><span class="p">(</span><span class="n">status</span><span class="p">))</span><span class="w"> </span><span class="p">{</span>
  1635. <span class="w"> </span><span class="n">Py_ExitStatusException</span><span class="p">(</span><span class="n">status</span><span class="p">);</span>
  1636. <span class="w"> </span><span class="p">}</span>
  1637. <span class="p">}</span>
  1638. </pre></div>
  1639. </div>
  1640. </section>
  1641. </section>
  1642. <div class="clearer"></div>
  1643. </div>
  1644. </div>
  1645. </div>
  1646. <div class="sphinxsidebar" role="navigation" aria-label="main navigation">
  1647. <div class="sphinxsidebarwrapper">
  1648. <div>
  1649. <h3><a href="../contents.html">Table of Contents</a></h3>
  1650. <ul>
  1651. <li><a class="reference internal" href="#">Python Initialization Configuration</a><ul>
  1652. <li><a class="reference internal" href="#example">Example</a></li>
  1653. <li><a class="reference internal" href="#pywidestringlist">PyWideStringList</a></li>
  1654. <li><a class="reference internal" href="#pystatus">PyStatus</a></li>
  1655. <li><a class="reference internal" href="#pypreconfig">PyPreConfig</a></li>
  1656. <li><a class="reference internal" href="#preinitialize-python-with-pypreconfig">Preinitialize Python with PyPreConfig</a></li>
  1657. <li><a class="reference internal" href="#pyconfig">PyConfig</a></li>
  1658. <li><a class="reference internal" href="#initialization-with-pyconfig">Initialization with PyConfig</a></li>
  1659. <li><a class="reference internal" href="#isolated-configuration">Isolated Configuration</a></li>
  1660. <li><a class="reference internal" href="#python-configuration">Python Configuration</a></li>
  1661. <li><a class="reference internal" href="#python-path-configuration">Python Path Configuration</a></li>
  1662. <li><a class="reference internal" href="#py-runmain">Py_RunMain()</a></li>
  1663. <li><a class="reference internal" href="#py-getargcargv">Py_GetArgcArgv()</a></li>
  1664. <li><a class="reference internal" href="#multi-phase-initialization-private-provisional-api">Multi-Phase Initialization Private Provisional API</a></li>
  1665. </ul>
  1666. </li>
  1667. </ul>
  1668. </div>
  1669. <div>
  1670. <h4>Previous topic</h4>
  1671. <p class="topless"><a href="init.html"
  1672. title="previous chapter">Initialization, Finalization, and Threads</a></p>
  1673. </div>
  1674. <div>
  1675. <h4>Next topic</h4>
  1676. <p class="topless"><a href="memory.html"
  1677. title="next chapter">Memory Management</a></p>
  1678. </div>
  1679. <div role="note" aria-label="source link">
  1680. <h3>This Page</h3>
  1681. <ul class="this-page-menu">
  1682. <li><a href="../bugs.html">Report a Bug</a></li>
  1683. <li>
  1684. <a href="https://github.com/python/cpython/blob/main/Doc/c-api/init_config.rst"
  1685. rel="nofollow">Show Source
  1686. </a>
  1687. </li>
  1688. </ul>
  1689. </div>
  1690. </div>
  1691. <div id="sidebarbutton" title="Collapse sidebar">
  1692. <span>«</span>
  1693. </div>
  1694. </div>
  1695. <div class="clearer"></div>
  1696. </div>
  1697. <div class="related" role="navigation" aria-label="related navigation">
  1698. <h3>Navigation</h3>
  1699. <ul>
  1700. <li class="right" style="margin-right: 10px">
  1701. <a href="../genindex.html" title="General Index"
  1702. >index</a></li>
  1703. <li class="right" >
  1704. <a href="../py-modindex.html" title="Python Module Index"
  1705. >modules</a> |</li>
  1706. <li class="right" >
  1707. <a href="memory.html" title="Memory Management"
  1708. >next</a> |</li>
  1709. <li class="right" >
  1710. <a href="init.html" title="Initialization, Finalization, and Threads"
  1711. >previous</a> |</li>
  1712. <li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
  1713. <li><a href="https://www.python.org/">Python</a> &#187;</li>
  1714. <li class="switchers">
  1715. <div class="language_switcher_placeholder"></div>
  1716. <div class="version_switcher_placeholder"></div>
  1717. </li>
  1718. <li>
  1719. </li>
  1720. <li id="cpython-language-and-version">
  1721. <a href="../index.html">3.12.3 Documentation</a> &#187;
  1722. </li>
  1723. <li class="nav-item nav-item-1"><a href="index.html" >Python/C API Reference Manual</a> &#187;</li>
  1724. <li class="nav-item nav-item-this"><a href="">Python Initialization Configuration</a></li>
  1725. <li class="right">
  1726. <div class="inline-search" role="search">
  1727. <form class="inline-search" action="../search.html" method="get">
  1728. <input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
  1729. <input type="submit" value="Go" />
  1730. </form>
  1731. </div>
  1732. |
  1733. </li>
  1734. <li class="right">
  1735. <label class="theme-selector-label">
  1736. Theme
  1737. <select class="theme-selector" oninput="activateTheme(this.value)">
  1738. <option value="auto" selected>Auto</option>
  1739. <option value="light">Light</option>
  1740. <option value="dark">Dark</option>
  1741. </select>
  1742. </label> |</li>
  1743. </ul>
  1744. </div>
  1745. <div class="footer">
  1746. &copy;
  1747. <a href="../copyright.html">
  1748. Copyright
  1749. </a>
  1750. 2001-2024, Python Software Foundation.
  1751. <br />
  1752. This page is licensed under the Python Software Foundation License Version 2.
  1753. <br />
  1754. Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
  1755. <br />
  1756. See <a href="/license.html">History and License</a> for more information.<br />
  1757. <br />
  1758. The Python Software Foundation is a non-profit corporation.
  1759. <a href="https://www.python.org/psf/donations/">Please donate.</a>
  1760. <br />
  1761. <br />
  1762. Last updated on Apr 09, 2024 (13:47 UTC).
  1763. <a href="/bugs.html">Found a bug</a>?
  1764. <br />
  1765. Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 7.2.6.
  1766. </div>
  1767. </body>
  1768. </html>
上海开阖软件有限公司 沪ICP备12045867号-1