Removed the Requirement to Install Python and NodeJS (Now Bundled with Borealis)

This commit is contained in:
2025-04-24 00:42:19 -06:00
parent 785265d3e7
commit 9c68cdea84
7786 changed files with 2386458 additions and 217 deletions

View File

@ -0,0 +1,387 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="6. Using Python on Android" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/using/android.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Python on Android is unlike Python on desktop platforms. On a desktop platform, Python is generally installed as a system resource that can be used by any user of that computer. Users then interact..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Python on Android is unlike Python on desktop platforms. On a desktop platform, Python is generally installed as a system resource that can be used by any user of that computer. Users then interact..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>6. Using Python on Android &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="7. Using Python on iOS" href="ios.html" />
<link rel="prev" title="5. Using Python on macOS" href="mac.html" />
<link rel="canonical" href="https://docs.python.org/3/using/android.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">6. Using Python on Android</a><ul>
<li><a class="reference internal" href="#adding-python-to-an-android-app">6.1. Adding Python to an Android app</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="mac.html"
title="previous chapter"><span class="section-number">5. </span>Using Python on macOS</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="ios.html"
title="next chapter"><span class="section-number">7. </span>Using Python on iOS</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/android.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="ios.html" title="7. Using Python on iOS"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="mac.html" title="5. Using Python on macOS"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">6. </span>Using Python on Android</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="using-python-on-android">
<span id="using-android"></span><h1><span class="section-number">6. </span>Using Python on Android<a class="headerlink" href="#using-python-on-android" title="Link to this heading"></a></h1>
<p>Python on Android is unlike Python on desktop platforms. On a desktop platform,
Python is generally installed as a system resource that can be used by any user
of that computer. Users then interact with Python by running a <strong class="program">python</strong>
executable and entering commands at an interactive prompt, or by running a
Python script.</p>
<p>On Android, there is no concept of installing as a system resource. The only unit
of software distribution is an “app”. There is also no console where you could
run a <strong class="program">python</strong> executable, or interact with a Python REPL.</p>
<p>As a result, the only way you can use Python on Android is in embedded mode that
is, by writing a native Android application, embedding a Python interpreter
using <code class="docutils literal notranslate"><span class="pre">libpython</span></code>, and invoking Python code using the <a class="reference internal" href="../extending/embedding.html#embedding"><span class="std std-ref">Python embedding
API</span></a>. The full Python interpreter, the standard library, and all
your Python code is then packaged into your app for its own private use.</p>
<p>The Python standard library has some notable omissions and restrictions on
Android. See the <a class="reference internal" href="../library/intro.html#mobile-availability"><span class="std std-ref">API availability guide</span></a> for
details.</p>
<section id="adding-python-to-an-android-app">
<h2><span class="section-number">6.1. </span>Adding Python to an Android app<a class="headerlink" href="#adding-python-to-an-android-app" title="Link to this heading"></a></h2>
<p>Most app developers should use one of the following tools, which will provide a
much easier experience:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://briefcase.readthedocs.io">Briefcase</a>, from the BeeWare project</p></li>
<li><p><a class="reference external" href="https://buildozer.readthedocs.io">Buildozer</a>, from the Kivy project</p></li>
<li><p><a class="reference external" href="https://chaquo.com/chaquopy">Chaquopy</a></p></li>
<li><p><a class="reference external" href="https://www.riverbankcomputing.com/static/Docs/pyqtdeploy/">pyqtdeploy</a></p></li>
<li><p><a class="reference external" href="https://termux.dev/en/">Termux</a></p></li>
</ul>
<p>If youre sure you want to do all of this manually, read on. You can use the
<a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Android/testbed">testbed app</a> as a guide; each step below contains a
link to the relevant file.</p>
<ul class="simple">
<li><p>Build Python by following the instructions in <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Android/README.md">Android/README.md</a>.
This will create the directory <code class="docutils literal notranslate"><span class="pre">cross-build/HOST/prefix</span></code>.</p></li>
<li><p>Add code to your <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Android/testbed/app/build.gradle.kts">build.gradle</a>
file to copy the following items into your project. All except your own Python
code can be copied from <code class="docutils literal notranslate"><span class="pre">prefix/lib</span></code>:</p>
<ul>
<li><p>In your JNI libraries:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">libpython*.*.so</span></code></p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">lib*_python.so</span></code> (external libraries such as OpenSSL)</p></li>
</ul>
</li>
<li><p>In your assets:</p>
<ul>
<li><p><code class="docutils literal notranslate"><span class="pre">python*.*</span></code> (the Python standard library)</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">python*.*/site-packages</span></code> (your own Python code)</p></li>
</ul>
</li>
</ul>
</li>
<li><p>Add code to your app to <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Android/testbed/app/src/main/java/org/python/testbed/MainActivity.kt">extract the assets to the filesystem</a>.</p></li>
<li><p>Add code to your app to <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Android/testbed/app/src/main/c/main_activity.c">start Python in embedded mode</a>. This will need to be C code
called via JNI.</p></li>
</ul>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">6. Using Python on Android</a><ul>
<li><a class="reference internal" href="#adding-python-to-an-android-app">6.1. Adding Python to an Android app</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="mac.html"
title="previous chapter"><span class="section-number">5. </span>Using Python on macOS</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="ios.html"
title="next chapter"><span class="section-number">7. </span>Using Python on iOS</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/android.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="ios.html" title="7. Using Python on iOS"
>next</a> |</li>
<li class="right" >
<a href="mac.html" title="5. Using Python on macOS"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">6. </span>Using Python on Android</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,348 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="8. Editors and IDEs" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/using/editors.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="There are a number of IDEs that support Python programming language. Many editors and IDEs provide syntax highlighting, debugging tools, and PEP 8 checks. IDLE — Python editor and shell: IDLE is Py..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="There are a number of IDEs that support Python programming language. Many editors and IDEs provide syntax highlighting, debugging tools, and PEP 8 checks. IDLE — Python editor and shell: IDLE is Py..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>8. Editors and IDEs &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="The Python Language Reference" href="../reference/index.html" />
<link rel="prev" title="7. Using Python on iOS" href="ios.html" />
<link rel="canonical" href="https://docs.python.org/3/using/editors.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">8. Editors and IDEs</a><ul>
<li><a class="reference internal" href="#idle-python-editor-and-shell">8.1. IDLE — Python editor and shell</a></li>
<li><a class="reference internal" href="#other-editors-and-ides">8.2. Other Editors and IDEs</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="ios.html"
title="previous chapter"><span class="section-number">7. </span>Using Python on iOS</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="../reference/index.html"
title="next chapter">The Python Language Reference</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/editors.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../reference/index.html" title="The Python Language Reference"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="ios.html" title="7. Using Python on iOS"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">8. </span>Editors and IDEs</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="editors-and-ides">
<span id="editors"></span><h1><span class="section-number">8. </span>Editors and IDEs<a class="headerlink" href="#editors-and-ides" title="Link to this heading"></a></h1>
<p>There are a number of IDEs that support Python programming language.
Many editors and IDEs provide syntax highlighting, debugging tools, and <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0008/"><strong>PEP 8</strong></a> checks.</p>
<section id="idle-python-editor-and-shell">
<h2><span class="section-number">8.1. </span>IDLE — Python editor and shell<a class="headerlink" href="#idle-python-editor-and-shell" title="Link to this heading"></a></h2>
<p>IDLE is Pythons Integrated Development and Learning Environment and is generally bundled with Python installs.
If you are on Linux and do not have IDLE installed see <a class="reference internal" href="unix.html#installing-idle-on-linux"><span class="std std-ref">Installing IDLE on Linux</span></a>.
For more information see the <a class="reference internal" href="../library/idle.html#idle"><span class="std std-ref">IDLE docs</span></a>.</p>
</section>
<section id="other-editors-and-ides">
<h2><span class="section-number">8.2. </span>Other Editors and IDEs<a class="headerlink" href="#other-editors-and-ides" title="Link to this heading"></a></h2>
<p>Pythons community wiki has information submitted by the community on Editors and IDEs.
Please go to <a class="reference external" href="https://wiki.python.org/moin/PythonEditors">Python Editors</a> and
<a class="reference external" href="https://wiki.python.org/moin/IntegratedDevelopmentEnvironments">Integrated Development Environments</a>
for a comprehensive list.</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">8. Editors and IDEs</a><ul>
<li><a class="reference internal" href="#idle-python-editor-and-shell">8.1. IDLE — Python editor and shell</a></li>
<li><a class="reference internal" href="#other-editors-and-ides">8.2. Other Editors and IDEs</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="ios.html"
title="previous chapter"><span class="section-number">7. </span>Using Python on iOS</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="../reference/index.html"
title="next chapter">The Python Language Reference</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/editors.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="../reference/index.html" title="The Python Language Reference"
>next</a> |</li>
<li class="right" >
<a href="ios.html" title="7. Using Python on iOS"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">8. </span>Editors and IDEs</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@ -0,0 +1,376 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="Python Setup and Usage" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/using/index.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="This part of the documentation is devoted to general information on the setup of the Python environment on different platforms, the invocation of the interpreter and things that make working with P..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="This part of the documentation is devoted to general information on the setup of the Python environment on different platforms, the invocation of the interpreter and things that make working with P..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>Python Setup and Usage &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="1. Command line and environment" href="cmdline.html" />
<link rel="prev" title="16. Appendix" href="../tutorial/appendix.html" />
<link rel="canonical" href="https://docs.python.org/3/using/index.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="../tutorial/appendix.html"
title="previous chapter"><span class="section-number">16. </span>Appendix</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="cmdline.html"
title="next chapter"><span class="section-number">1. </span>Command line and environment</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/index.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="cmdline.html" title="1. Command line and environment"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="../tutorial/appendix.html" title="16. Appendix"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-this"><a href="">Python Setup and Usage</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="python-setup-and-usage">
<span id="using-index"></span><h1>Python Setup and Usage<a class="headerlink" href="#python-setup-and-usage" title="Link to this heading"></a></h1>
<p>This part of the documentation is devoted to general information on the setup
of the Python environment on different platforms, the invocation of the
interpreter and things that make working with Python easier.</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="cmdline.html">1. Command line and environment</a><ul>
<li class="toctree-l2"><a class="reference internal" href="cmdline.html#command-line">1.1. Command line</a></li>
<li class="toctree-l2"><a class="reference internal" href="cmdline.html#environment-variables">1.2. Environment variables</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="unix.html">2. Using Python on Unix platforms</a><ul>
<li class="toctree-l2"><a class="reference internal" href="unix.html#getting-and-installing-the-latest-version-of-python">2.1. Getting and installing the latest version of Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="unix.html#building-python">2.2. Building Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="unix.html#python-related-paths-and-files">2.3. Python-related paths and files</a></li>
<li class="toctree-l2"><a class="reference internal" href="unix.html#miscellaneous">2.4. Miscellaneous</a></li>
<li class="toctree-l2"><a class="reference internal" href="unix.html#custom-openssl">2.5. Custom OpenSSL</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="configure.html">3. Configure Python</a><ul>
<li class="toctree-l2"><a class="reference internal" href="configure.html#build-requirements">3.1. Build Requirements</a></li>
<li class="toctree-l2"><a class="reference internal" href="configure.html#generated-files">3.2. Generated files</a></li>
<li class="toctree-l2"><a class="reference internal" href="configure.html#configure-options">3.3. Configure Options</a></li>
<li class="toctree-l2"><a class="reference internal" href="configure.html#python-build-system">3.4. Python Build System</a></li>
<li class="toctree-l2"><a class="reference internal" href="configure.html#compiler-and-linker-flags">3.5. Compiler and linker flags</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="windows.html">4. Using Python on Windows</a><ul>
<li class="toctree-l2"><a class="reference internal" href="windows.html#the-full-installer">4.1. The full installer</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#the-microsoft-store-package">4.2. The Microsoft Store package</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#the-nuget-org-packages">4.3. The nuget.org packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#the-embeddable-package">4.4. The embeddable package</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#alternative-bundles">4.5. Alternative bundles</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#configuring-python">4.6. Configuring Python</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#utf-8-mode">4.7. UTF-8 mode</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#python-launcher-for-windows">4.8. Python Launcher for Windows</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#finding-modules">4.9. Finding modules</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#additional-modules">4.10. Additional modules</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#compiling-python-on-windows">4.11. Compiling Python on Windows</a></li>
<li class="toctree-l2"><a class="reference internal" href="windows.html#other-platforms">4.12. Other Platforms</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="mac.html">5. Using Python on macOS</a><ul>
<li class="toctree-l2"><a class="reference internal" href="mac.html#using-python-for-macos-from-python-org">5.1. Using Python for macOS from <code class="docutils literal notranslate"><span class="pre">python.org</span></code></a></li>
<li class="toctree-l2"><a class="reference internal" href="mac.html#alternative-distributions">5.2. Alternative Distributions</a></li>
<li class="toctree-l2"><a class="reference internal" href="mac.html#installing-additional-python-packages">5.3. Installing Additional Python Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="mac.html#gui-programming">5.4. GUI Programming</a></li>
<li class="toctree-l2"><a class="reference internal" href="mac.html#advanced-topics">5.5. Advanced Topics</a></li>
<li class="toctree-l2"><a class="reference internal" href="mac.html#other-resources">5.6. Other Resources</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="android.html">6. Using Python on Android</a><ul>
<li class="toctree-l2"><a class="reference internal" href="android.html#adding-python-to-an-android-app">6.1. Adding Python to an Android app</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="ios.html">7. Using Python on iOS</a><ul>
<li class="toctree-l2"><a class="reference internal" href="ios.html#python-at-runtime-on-ios">7.1. Python at runtime on iOS</a></li>
<li class="toctree-l2"><a class="reference internal" href="ios.html#installing-python-on-ios">7.2. Installing Python on iOS</a></li>
<li class="toctree-l2"><a class="reference internal" href="ios.html#app-store-compliance">7.3. App Store Compliance</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="editors.html">8. Editors and IDEs</a><ul>
<li class="toctree-l2"><a class="reference internal" href="editors.html#idle-python-editor-and-shell">8.1. IDLE — Python editor and shell</a></li>
<li class="toctree-l2"><a class="reference internal" href="editors.html#other-editors-and-ides">8.2. Other Editors and IDEs</a></li>
</ul>
</li>
</ul>
</div>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="../tutorial/appendix.html"
title="previous chapter"><span class="section-number">16. </span>Appendix</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="cmdline.html"
title="next chapter"><span class="section-number">1. </span>Command line and environment</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/index.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="cmdline.html" title="1. Command line and environment"
>next</a> |</li>
<li class="right" >
<a href="../tutorial/appendix.html" title="16. Appendix"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-this"><a href="">Python Setup and Usage</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@ -0,0 +1,704 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="7. Using Python on iOS" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/using/ios.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Authors, Russell Keith-Magee (2024-03),. Python on iOS is unlike Python on desktop platforms. On a desktop platform, Python is generally installed as a system resource that can be used by any user ..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Authors, Russell Keith-Magee (2024-03),. Python on iOS is unlike Python on desktop platforms. On a desktop platform, Python is generally installed as a system resource that can be used by any user ..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>7. Using Python on iOS &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="8. Editors and IDEs" href="editors.html" />
<link rel="prev" title="6. Using Python on Android" href="android.html" />
<link rel="canonical" href="https://docs.python.org/3/using/ios.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">7. Using Python on iOS</a><ul>
<li><a class="reference internal" href="#python-at-runtime-on-ios">7.1. Python at runtime on iOS</a><ul>
<li><a class="reference internal" href="#ios-version-compatibility">7.1.1. iOS version compatibility</a></li>
<li><a class="reference internal" href="#platform-identification">7.1.2. Platform identification</a></li>
<li><a class="reference internal" href="#standard-library-availability">7.1.3. Standard library availability</a></li>
<li><a class="reference internal" href="#binary-extension-modules">7.1.4. Binary extension modules</a></li>
<li><a class="reference internal" href="#compiler-stub-binaries">7.1.5. Compiler stub binaries</a></li>
</ul>
</li>
<li><a class="reference internal" href="#installing-python-on-ios">7.2. Installing Python on iOS</a><ul>
<li><a class="reference internal" href="#tools-for-building-ios-apps">7.2.1. Tools for building iOS apps</a></li>
<li><a class="reference internal" href="#adding-python-to-an-ios-project">7.2.2. Adding Python to an iOS project</a></li>
<li><a class="reference internal" href="#testing-a-python-package">7.2.3. Testing a Python package</a></li>
</ul>
</li>
<li><a class="reference internal" href="#app-store-compliance">7.3. App Store Compliance</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="android.html"
title="previous chapter"><span class="section-number">6. </span>Using Python on Android</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="editors.html"
title="next chapter"><span class="section-number">8. </span>Editors and IDEs</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/ios.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="editors.html" title="8. Editors and IDEs"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="android.html" title="6. Using Python on Android"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>Using Python on iOS</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="using-python-on-ios">
<span id="using-ios"></span><h1><span class="section-number">7. </span>Using Python on iOS<a class="headerlink" href="#using-python-on-ios" title="Link to this heading"></a></h1>
<dl class="field-list simple">
<dt class="field-odd">Authors<span class="colon">:</span></dt>
<dd class="field-odd"><p>Russell Keith-Magee (2024-03)</p>
</dd>
</dl>
<p>Python on iOS is unlike Python on desktop platforms. On a desktop platform,
Python is generally installed as a system resource that can be used by any user
of that computer. Users then interact with Python by running a <strong class="program">python</strong>
executable and entering commands at an interactive prompt, or by running a
Python script.</p>
<p>On iOS, there is no concept of installing as a system resource. The only unit
of software distribution is an “app”. There is also no console where you could
run a <strong class="program">python</strong> executable, or interact with a Python REPL.</p>
<p>As a result, the only way you can use Python on iOS is in embedded mode - that
is, by writing a native iOS application, and embedding a Python interpreter
using <code class="docutils literal notranslate"><span class="pre">libPython</span></code>, and invoking Python code using the <a class="reference internal" href="../extending/embedding.html#embedding"><span class="std std-ref">Python embedding
API</span></a>. The full Python interpreter, the standard library, and all
your Python code is then packaged as a standalone bundle that can be
distributed via the iOS App Store.</p>
<p>If youre looking to experiment for the first time with writing an iOS app in
Python, projects such as <a class="reference external" href="https://beeware.org">BeeWare</a> and <a class="reference external" href="https://kivy.org">Kivy</a> will provide a much more approachable user experience.
These projects manage the complexities associated with getting an iOS project
running, so you only need to deal with the Python code itself.</p>
<section id="python-at-runtime-on-ios">
<h2><span class="section-number">7.1. </span>Python at runtime on iOS<a class="headerlink" href="#python-at-runtime-on-ios" title="Link to this heading"></a></h2>
<section id="ios-version-compatibility">
<h3><span class="section-number">7.1.1. </span>iOS version compatibility<a class="headerlink" href="#ios-version-compatibility" title="Link to this heading"></a></h3>
<p>The minimum supported iOS version is specified at compile time, using the
<a class="reference internal" href="configure.html#cmdoption-host"><code class="xref std std-option docutils literal notranslate"><span class="pre">--host</span></code></a> option to <code class="docutils literal notranslate"><span class="pre">configure</span></code>. By default, when compiled for iOS,
Python will be compiled with a minimum supported iOS version of 13.0. To use a
different minimum iOS version, provide the version number as part of the
<code class="xref std std-option docutils literal notranslate"><span class="pre">--host</span></code> argument - for example,
<code class="docutils literal notranslate"><span class="pre">--host=arm64-apple-ios15.4-simulator</span></code> would compile an ARM64 simulator build
with a deployment target of 15.4.</p>
</section>
<section id="platform-identification">
<h3><span class="section-number">7.1.2. </span>Platform identification<a class="headerlink" href="#platform-identification" title="Link to this heading"></a></h3>
<p>When executing on iOS, <code class="docutils literal notranslate"><span class="pre">sys.platform</span></code> will report as <code class="docutils literal notranslate"><span class="pre">ios</span></code>. This value will
be returned on an iPhone or iPad, regardless of whether the app is running on
the simulator or a physical device.</p>
<p>Information about the specific runtime environment, including the iOS version,
device model, and whether the device is a simulator, can be obtained using
<a class="reference internal" href="../library/platform.html#platform.ios_ver" title="platform.ios_ver"><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.ios_ver()</span></code></a>. <a class="reference internal" href="../library/platform.html#platform.system" title="platform.system"><code class="xref py py-func docutils literal notranslate"><span class="pre">platform.system()</span></code></a> will report <code class="docutils literal notranslate"><span class="pre">iOS</span></code> or
<code class="docutils literal notranslate"><span class="pre">iPadOS</span></code>, depending on the device.</p>
<p><a class="reference internal" href="../library/os.html#os.uname" title="os.uname"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.uname()</span></code></a> reports kernel-level details; it will report a name of
<code class="docutils literal notranslate"><span class="pre">Darwin</span></code>.</p>
</section>
<section id="standard-library-availability">
<h3><span class="section-number">7.1.3. </span>Standard library availability<a class="headerlink" href="#standard-library-availability" title="Link to this heading"></a></h3>
<p>The Python standard library has some notable omissions and restrictions on
iOS. See the <a class="reference internal" href="../library/intro.html#mobile-availability"><span class="std std-ref">API availability guide for iOS</span></a> for
details.</p>
</section>
<section id="binary-extension-modules">
<h3><span class="section-number">7.1.4. </span>Binary extension modules<a class="headerlink" href="#binary-extension-modules" title="Link to this heading"></a></h3>
<p>One notable difference about iOS as a platform is that App Store distribution
imposes hard requirements on the packaging of an application. One of these
requirements governs how binary extension modules are distributed.</p>
<p>The iOS App Store requires that <em>all</em> binary modules in an iOS app must be
dynamic libraries, contained in a framework with appropriate metadata, stored
in the <code class="docutils literal notranslate"><span class="pre">Frameworks</span></code> folder of the packaged app. There can be only a single
binary per framework, and there can be no executable binary material outside
the <code class="docutils literal notranslate"><span class="pre">Frameworks</span></code> folder.</p>
<p>This conflicts with the usual Python approach for distributing binaries, which
allows a binary extension module to be loaded from any location on
<code class="docutils literal notranslate"><span class="pre">sys.path</span></code>. To ensure compliance with App Store policies, an iOS project must
post-process any Python packages, converting <code class="docutils literal notranslate"><span class="pre">.so</span></code> binary modules into
individual standalone frameworks with appropriate metadata and signing. For
details on how to perform this post-processing, see the guide for <a class="reference internal" href="#adding-ios"><span class="std std-ref">adding
Python to your project</span></a>.</p>
<p>To help Python discover binaries in their new location, the original <code class="docutils literal notranslate"><span class="pre">.so</span></code>
file on <code class="docutils literal notranslate"><span class="pre">sys.path</span></code> is replaced with a <code class="docutils literal notranslate"><span class="pre">.fwork</span></code> file. This file is a text
file containing the location of the framework binary, relative to the app
bundle. To allow the framework to resolve back to the original location, the
framework must contain a <code class="docutils literal notranslate"><span class="pre">.origin</span></code> file that contains the location of the
<code class="docutils literal notranslate"><span class="pre">.fwork</span></code> file, relative to the app bundle.</p>
<p>For example, consider the case of an import <code class="docutils literal notranslate"><span class="pre">from</span> <span class="pre">foo.bar</span> <span class="pre">import</span> <span class="pre">_whiz</span></code>,
where <code class="docutils literal notranslate"><span class="pre">_whiz</span></code> is implemented with the binary module
<code class="docutils literal notranslate"><span class="pre">sources/foo/bar/_whiz.abi3.so</span></code>, with <code class="docutils literal notranslate"><span class="pre">sources</span></code> being the location
registered on <code class="docutils literal notranslate"><span class="pre">sys.path</span></code>, relative to the application bundle. This module
<em>must</em> be distributed as <code class="docutils literal notranslate"><span class="pre">Frameworks/foo.bar._whiz.framework/foo.bar._whiz</span></code>
(creating the framework name from the full import path of the module), with an
<code class="docutils literal notranslate"><span class="pre">Info.plist</span></code> file in the <code class="docutils literal notranslate"><span class="pre">.framework</span></code> directory identifying the binary as a
framework. The <code class="docutils literal notranslate"><span class="pre">foo.bar._whiz</span></code> module would be represented in the original
location with a <code class="docutils literal notranslate"><span class="pre">sources/foo/bar/_whiz.abi3.fwork</span></code> marker file, containing
the path <code class="docutils literal notranslate"><span class="pre">Frameworks/foo.bar._whiz/foo.bar._whiz</span></code>. The framework would also
contain <code class="docutils literal notranslate"><span class="pre">Frameworks/foo.bar._whiz.framework/foo.bar._whiz.origin</span></code>, containing
the path to the <code class="docutils literal notranslate"><span class="pre">.fwork</span></code> file.</p>
<p>When running on iOS, the Python interpreter will install an
<a class="reference internal" href="../library/importlib.html#importlib.machinery.AppleFrameworkLoader" title="importlib.machinery.AppleFrameworkLoader"><code class="xref py py-class docutils literal notranslate"><span class="pre">AppleFrameworkLoader</span></code></a> that is able to read and
import <code class="docutils literal notranslate"><span class="pre">.fwork</span></code> files. Once imported, the <code class="docutils literal notranslate"><span class="pre">__file__</span></code> attribute of the
binary module will report as the location of the <code class="docutils literal notranslate"><span class="pre">.fwork</span></code> file. However, the
<a class="reference internal" href="../library/importlib.html#importlib.machinery.ModuleSpec" title="importlib.machinery.ModuleSpec"><code class="xref py py-class docutils literal notranslate"><span class="pre">ModuleSpec</span></code></a> for the loaded module will report the
<code class="docutils literal notranslate"><span class="pre">origin</span></code> as the location of the binary in the framework folder.</p>
</section>
<section id="compiler-stub-binaries">
<h3><span class="section-number">7.1.5. </span>Compiler stub binaries<a class="headerlink" href="#compiler-stub-binaries" title="Link to this heading"></a></h3>
<p>Xcode doesnt expose explicit compilers for iOS; instead, it uses an <code class="docutils literal notranslate"><span class="pre">xcrun</span></code>
script that resolves to a full compiler path (e.g., <code class="docutils literal notranslate"><span class="pre">xcrun</span> <span class="pre">--sdk</span> <span class="pre">iphoneos</span>
<span class="pre">clang</span></code> to get the <code class="docutils literal notranslate"><span class="pre">clang</span></code> for an iPhone device). However, using this script
poses two problems:</p>
<ul class="simple">
<li><p>The output of <code class="docutils literal notranslate"><span class="pre">xcrun</span></code> includes paths that are machine specific, resulting
in a sysconfig module that cannot be shared between users; and</p></li>
<li><p>It results in <code class="docutils literal notranslate"><span class="pre">CC</span></code>/<code class="docutils literal notranslate"><span class="pre">CPP</span></code>/<code class="docutils literal notranslate"><span class="pre">LD</span></code>/<code class="docutils literal notranslate"><span class="pre">AR</span></code> definitions that include spaces.
There is a lot of C ecosystem tooling that assumes that you can split a
command line at the first space to get the path to the compiler executable;
this isnt the case when using <code class="docutils literal notranslate"><span class="pre">xcrun</span></code>.</p></li>
</ul>
<p>To avoid these problems, Python provided stubs for these tools. These stubs are
shell script wrappers around the underingly <code class="docutils literal notranslate"><span class="pre">xcrun</span></code> tools, distributed in a
<code class="docutils literal notranslate"><span class="pre">bin</span></code> folder distributed alongside the compiled iOS framework. These scripts
are relocatable, and will always resolve to the appropriate local system paths.
By including these scripts in the bin folder that accompanies a framework, the
contents of the <code class="docutils literal notranslate"><span class="pre">sysconfig</span></code> module becomes useful for end-users to compile
their own modules. When compiling third-party Python modules for iOS, you
should ensure these stub binaries are on your path.</p>
</section>
</section>
<section id="installing-python-on-ios">
<h2><span class="section-number">7.2. </span>Installing Python on iOS<a class="headerlink" href="#installing-python-on-ios" title="Link to this heading"></a></h2>
<section id="tools-for-building-ios-apps">
<h3><span class="section-number">7.2.1. </span>Tools for building iOS apps<a class="headerlink" href="#tools-for-building-ios-apps" title="Link to this heading"></a></h3>
<p>Building for iOS requires the use of Apples Xcode tooling. It is strongly
recommended that you use the most recent stable release of Xcode. This will
require the use of the most (or second-most) recently released macOS version,
as Apple does not maintain Xcode for older macOS versions. The Xcode Command
Line Tools are not sufficient for iOS development; you need a <em>full</em> Xcode
install.</p>
<p>If you want to run your code on the iOS simulator, youll also need to install
an iOS Simulator Platform. You should be prompted to select an iOS Simulator
Platform when you first run Xcode. Alternatively, you can add an iOS Simulator
Platform by selecting from the Platforms tab of the Xcode Settings panel.</p>
</section>
<section id="adding-python-to-an-ios-project">
<span id="adding-ios"></span><h3><span class="section-number">7.2.2. </span>Adding Python to an iOS project<a class="headerlink" href="#adding-python-to-an-ios-project" title="Link to this heading"></a></h3>
<p>Python can be added to any iOS project, using either Swift or Objective C. The
following examples will use Objective C; if you are using Swift, you may find a
library like <a class="reference external" href="https://github.com/pvieito/PythonKit">PythonKit</a> to be
helpful.</p>
<p>To add Python to an iOS Xcode project:</p>
<ol class="arabic">
<li><p>Build or obtain a Python <code class="docutils literal notranslate"><span class="pre">XCFramework</span></code>. See the instructions in
<a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/iOS/README.rst">iOS/README.rst</a> (in the CPython source distribution) for details on
how to build a Python <code class="docutils literal notranslate"><span class="pre">XCFramework</span></code>. At a minimum, you will need a build
that supports <code class="docutils literal notranslate"><span class="pre">arm64-apple-ios</span></code>, plus one of either
<code class="docutils literal notranslate"><span class="pre">arm64-apple-ios-simulator</span></code> or <code class="docutils literal notranslate"><span class="pre">x86_64-apple-ios-simulator</span></code>.</p></li>
<li><p>Drag the <code class="docutils literal notranslate"><span class="pre">XCframework</span></code> into your iOS project. In the following
instructions, well assume youve dropped the <code class="docutils literal notranslate"><span class="pre">XCframework</span></code> into the root
of your project; however, you can use any other location that you want by
adjusting paths as needed.</p></li>
<li><p>Drag the <code class="docutils literal notranslate"><span class="pre">iOS/Resources/dylib-Info-template.plist</span></code> file into your project,
and ensure it is associated with the app target.</p></li>
<li><p>Add your application code as a folder in your Xcode project. In the
following instructions, well assume that your user code is in a folder
named <code class="docutils literal notranslate"><span class="pre">app</span></code> in the root of your project; you can use any other location by
adjusting paths as needed. Ensure that this folder is associated with your
app target.</p></li>
<li><p>Select the app target by selecting the root node of your Xcode project, then
the target name in the sidebar that appears.</p></li>
<li><p>In the “General” settings, under “Frameworks, Libraries and Embedded
Content”, add <code class="docutils literal notranslate"><span class="pre">Python.xcframework</span></code>, with “Embed &amp; Sign” selected.</p></li>
<li><p>In the “Build Settings” tab, modify the following:</p>
<ul class="simple">
<li><p>Build Options</p>
<ul>
<li><p>User Script Sandboxing: No</p></li>
<li><p>Enable Testability: Yes</p></li>
</ul>
</li>
<li><p>Search Paths</p>
<ul>
<li><p>Framework Search Paths: <code class="docutils literal notranslate"><span class="pre">$(PROJECT_DIR)</span></code></p></li>
<li><p>Header Search Paths: <code class="docutils literal notranslate"><span class="pre">&quot;$(BUILT_PRODUCTS_DIR)/Python.framework/Headers&quot;</span></code></p></li>
</ul>
</li>
<li><p>Apple Clang - Warnings - All languages</p>
<ul>
<li><p>Quoted Include In Framework Header: No</p></li>
</ul>
</li>
</ul>
</li>
<li><p>Add a build step that copies the Python standard library into your app. In
the “Build Phases” tab, add a new “Run Script” build step <em>before</em> the
“Embed Frameworks” step, but <em>after</em> the “Copy Bundle Resources” step. Name
the step “Install Target Specific Python Standard Library”, disable the
“Based on dependency analysis” checkbox, and set the script content to:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="w"> </span>-e
mkdir<span class="w"> </span>-p<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/python/lib&quot;</span>
<span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$EFFECTIVE_PLATFORM_NAME</span><span class="s2">&quot;</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s2">&quot;-iphonesimulator&quot;</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Installing Python modules for iOS Simulator&quot;</span>
<span class="w"> </span>rsync<span class="w"> </span>-au<span class="w"> </span>--delete<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$PROJECT_DIR</span><span class="s2">/Python.xcframework/ios-arm64_x86_64-simulator/lib/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/python/lib/&quot;</span>
<span class="k">else</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Installing Python modules for iOS Device&quot;</span>
<span class="w"> </span>rsync<span class="w"> </span>-au<span class="w"> </span>--delete<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$PROJECT_DIR</span><span class="s2">/Python.xcframework/ios-arm64/lib/&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/python/lib/&quot;</span>
<span class="k">fi</span>
</pre></div>
</div>
<p>Note that the name of the simulator “slice” in the XCframework may be
different, depending the CPU architectures your <code class="docutils literal notranslate"><span class="pre">XCFramework</span></code> supports.</p>
</li>
<li><p>Add a second build step that processes the binary extension modules in the
standard library into “Framework” format. Add a “Run Script” build step
<em>directly after</em> the one you added in step 8, named “Prepare Python Binary
Modules”. It should also have “Based on dependency analysis” unchecked, with
the following script content:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span><span class="nb">set</span><span class="w"> </span>-e
install_dylib<span class="w"> </span><span class="o">()</span><span class="w"> </span><span class="o">{</span>
<span class="w"> </span><span class="nv">INSTALL_BASE</span><span class="o">=</span><span class="nv">$1</span>
<span class="w"> </span><span class="nv">FULL_EXT</span><span class="o">=</span><span class="nv">$2</span>
<span class="w"> </span><span class="c1"># The name of the extension file</span>
<span class="w"> </span><span class="nv">EXT</span><span class="o">=</span><span class="k">$(</span>basename<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$FULL_EXT</span><span class="s2">&quot;</span><span class="k">)</span>
<span class="w"> </span><span class="c1"># The location of the extension file, relative to the bundle</span>
<span class="w"> </span><span class="nv">RELATIVE_EXT</span><span class="o">=</span><span class="si">${</span><span class="nv">FULL_EXT</span><span class="p">#</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="p">/</span><span class="si">}</span>
<span class="w"> </span><span class="c1"># The path to the extension file, relative to the install base</span>
<span class="w"> </span><span class="nv">PYTHON_EXT</span><span class="o">=</span><span class="si">${</span><span class="nv">RELATIVE_EXT</span><span class="p">/</span><span class="nv">$INSTALL_BASE</span><span class="p">/</span><span class="si">}</span>
<span class="w"> </span><span class="c1"># The full dotted name of the extension module, constructed from the file path.</span>
<span class="w"> </span><span class="nv">FULL_MODULE_NAME</span><span class="o">=</span><span class="k">$(</span><span class="nb">echo</span><span class="w"> </span><span class="nv">$PYTHON_EXT</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>cut<span class="w"> </span>-d<span class="w"> </span><span class="s2">&quot;.&quot;</span><span class="w"> </span>-f<span class="w"> </span><span class="m">1</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>tr<span class="w"> </span><span class="s2">&quot;/&quot;</span><span class="w"> </span><span class="s2">&quot;.&quot;</span><span class="k">)</span><span class="p">;</span>
<span class="w"> </span><span class="c1"># A bundle identifier; not actually used, but required by Xcode framework packaging</span>
<span class="w"> </span><span class="nv">FRAMEWORK_BUNDLE_ID</span><span class="o">=</span><span class="k">$(</span><span class="nb">echo</span><span class="w"> </span><span class="nv">$PRODUCT_BUNDLE_IDENTIFIER</span>.<span class="nv">$FULL_MODULE_NAME</span><span class="w"> </span><span class="p">|</span><span class="w"> </span>tr<span class="w"> </span><span class="s2">&quot;_&quot;</span><span class="w"> </span><span class="s2">&quot;-&quot;</span><span class="k">)</span>
<span class="w"> </span><span class="c1"># The name of the framework folder.</span>
<span class="w"> </span><span class="nv">FRAMEWORK_FOLDER</span><span class="o">=</span><span class="s2">&quot;Frameworks/</span><span class="nv">$FULL_MODULE_NAME</span><span class="s2">.framework&quot;</span>
<span class="w"> </span><span class="c1"># If the framework folder doesn&#39;t exist, create it.</span>
<span class="w"> </span><span class="k">if</span><span class="w"> </span><span class="o">[</span><span class="w"> </span>!<span class="w"> </span>-d<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">&quot;</span><span class="w"> </span><span class="o">]</span><span class="p">;</span><span class="w"> </span><span class="k">then</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Creating framework for </span><span class="nv">$RELATIVE_EXT</span><span class="s2">&quot;</span>
<span class="w"> </span>mkdir<span class="w"> </span>-p<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">&quot;</span>
<span class="w"> </span>cp<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/dylib-Info-template.plist&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">/Info.plist&quot;</span>
<span class="w"> </span>plutil<span class="w"> </span>-replace<span class="w"> </span>CFBundleExecutable<span class="w"> </span>-string<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$FULL_MODULE_NAME</span><span class="s2">&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">/Info.plist&quot;</span>
<span class="w"> </span>plutil<span class="w"> </span>-replace<span class="w"> </span>CFBundleIdentifier<span class="w"> </span>-string<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$FRAMEWORK_BUNDLE_ID</span><span class="s2">&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">/Info.plist&quot;</span>
<span class="w"> </span><span class="k">fi</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Installing binary for </span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">/</span><span class="nv">$FULL_MODULE_NAME</span><span class="s2">&quot;</span>
<span class="w"> </span>mv<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$FULL_EXT</span><span class="s2">&quot;</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">/</span><span class="nv">$FULL_MODULE_NAME</span><span class="s2">&quot;</span>
<span class="w"> </span><span class="c1"># Create a placeholder .fwork file where the .so was</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">/</span><span class="nv">$FULL_MODULE_NAME</span><span class="s2">&quot;</span><span class="w"> </span>&gt;<span class="w"> </span><span class="si">${</span><span class="nv">FULL_EXT</span><span class="p">%.so</span><span class="si">}</span>.fwork
<span class="w"> </span><span class="c1"># Create a back reference to the .so file location in the framework</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;</span><span class="si">${</span><span class="nv">RELATIVE_EXT</span><span class="p">%.so</span><span class="si">}</span><span class="s2">.fwork&quot;</span><span class="w"> </span>&gt;<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/</span><span class="nv">$FRAMEWORK_FOLDER</span><span class="s2">/</span><span class="nv">$FULL_MODULE_NAME</span><span class="s2">.origin&quot;</span>
<span class="w"> </span><span class="o">}</span>
<span class="w"> </span><span class="nv">PYTHON_VER</span><span class="o">=</span><span class="k">$(</span>ls<span class="w"> </span>-1<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/python/lib&quot;</span><span class="k">)</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Install Python </span><span class="nv">$PYTHON_VER</span><span class="s2"> standard library extension modules...&quot;</span>
<span class="w"> </span>find<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/python/lib/</span><span class="nv">$PYTHON_VER</span><span class="s2">/lib-dynload&quot;</span><span class="w"> </span>-name<span class="w"> </span><span class="s2">&quot;*.so&quot;</span><span class="w"> </span><span class="p">|</span><span class="w"> </span><span class="k">while</span><span class="w"> </span><span class="nb">read</span><span class="w"> </span>FULL_EXT<span class="p">;</span><span class="w"> </span><span class="k">do</span>
<span class="w"> </span>install_dylib<span class="w"> </span>python/lib/<span class="nv">$PYTHON_VER</span>/lib-dynload/<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$FULL_EXT</span><span class="s2">&quot;</span>
<span class="w"> </span><span class="k">done</span>
<span class="w"> </span><span class="c1"># Clean up dylib template</span>
<span class="w"> </span>rm<span class="w"> </span>-f<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/dylib-Info-template.plist&quot;</span>
<span class="w"> </span><span class="nb">echo</span><span class="w"> </span><span class="s2">&quot;Signing frameworks as </span><span class="nv">$EXPANDED_CODE_SIGN_IDENTITY_NAME</span><span class="s2"> (</span><span class="nv">$EXPANDED_CODE_SIGN_IDENTITY</span><span class="s2">)...&quot;</span>
<span class="w"> </span>find<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$CODESIGNING_FOLDER_PATH</span><span class="s2">/Frameworks&quot;</span><span class="w"> </span>-name<span class="w"> </span><span class="s2">&quot;*.framework&quot;</span><span class="w"> </span>-exec<span class="w"> </span>/usr/bin/codesign<span class="w"> </span>--force<span class="w"> </span>--sign<span class="w"> </span><span class="s2">&quot;</span><span class="nv">$EXPANDED_CODE_SIGN_IDENTITY</span><span class="s2">&quot;</span><span class="w"> </span><span class="si">${</span><span class="nv">OTHER_CODE_SIGN_FLAGS</span><span class="k">:-</span><span class="si">}</span><span class="w"> </span>-o<span class="w"> </span>runtime<span class="w"> </span>--timestamp<span class="o">=</span>none<span class="w"> </span>--preserve-metadata<span class="o">=</span>identifier,entitlements,flags<span class="w"> </span>--generate-entitlement-der<span class="w"> </span><span class="s2">&quot;{}&quot;</span><span class="w"> </span><span class="se">\;</span>
</pre></div>
</div>
</li>
<li><p>Add Objective C code to initialize and use a Python interpreter in embedded
mode. You should ensure that:</p></li>
</ol>
<blockquote>
<div><ul class="simple">
<li><p>UTF-8 mode (<a class="reference internal" href="../c-api/init_config.html#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 <em>enabled</em>;</p></li>
<li><p>Buffered stdio (<a class="reference internal" href="../c-api/init_config.html#c.PyConfig.buffered_stdio" title="PyConfig.buffered_stdio"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.buffered_stdio</span></code></a>) is <em>disabled</em>;</p></li>
<li><p>Writing bytecode (<a class="reference internal" href="../c-api/init_config.html#c.PyConfig.write_bytecode" title="PyConfig.write_bytecode"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.write_bytecode</span></code></a>) is <em>disabled</em>;</p></li>
<li><p>Signal handlers (<a class="reference internal" href="../c-api/init_config.html#c.PyConfig.install_signal_handlers" title="PyConfig.install_signal_handlers"><code class="xref c c-member docutils literal notranslate"><span class="pre">PyConfig.install_signal_handlers</span></code></a>) are <em>enabled</em>;</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">PYTHONHOME</span></code> for the interpreter is configured to point at the
<code class="docutils literal notranslate"><span class="pre">python</span></code> subfolder of your apps bundle; and</p></li>
<li><p>The <code class="docutils literal notranslate"><span class="pre">PYTHONPATH</span></code> for the interpreter includes:</p>
<ul>
<li><p>the <code class="docutils literal notranslate"><span class="pre">python/lib/python3.X</span></code> subfolder of your apps bundle,</p></li>
<li><p>the <code class="docutils literal notranslate"><span class="pre">python/lib/python3.X/lib-dynload</span></code> subfolder of your apps bundle, and</p></li>
<li><p>the <code class="docutils literal notranslate"><span class="pre">app</span></code> subfolder of your apps bundle</p></li>
</ul>
</li>
</ul>
<p>Your apps bundle location can be determined using <code class="docutils literal notranslate"><span class="pre">[[NSBundle</span> <span class="pre">mainBundle]</span>
<span class="pre">resourcePath]</span></code>.</p>
</div></blockquote>
<p>Steps 8, 9 and 10 of these instructions assume that you have a single folder of
pure Python application code, named <code class="docutils literal notranslate"><span class="pre">app</span></code>. If you have third-party binary
modules in your app, some additional steps will be required:</p>
<ul class="simple">
<li><p>You need to ensure that any folders containing third-party binaries are
either associated with the app target, or copied in as part of step 8. Step 8
should also purge any binaries that are not appropriate for the platform a
specific build is targeting (i.e., delete any device binaries if youre
building an app targeting the simulator).</p></li>
<li><p>Any folders that contain third-party binaries must be processed into
framework form by step 9. The invocation of <code class="docutils literal notranslate"><span class="pre">install_dylib</span></code> that processes
the <code class="docutils literal notranslate"><span class="pre">lib-dynload</span></code> folder can be copied and adapted for this purpose.</p></li>
<li><p>If youre using a separate folder for third-party packages, ensure that folder
is included as part of the <code class="docutils literal notranslate"><span class="pre">PYTHONPATH</span></code> configuration in step 10.</p></li>
</ul>
</section>
<section id="testing-a-python-package">
<h3><span class="section-number">7.2.3. </span>Testing a Python package<a class="headerlink" href="#testing-a-python-package" title="Link to this heading"></a></h3>
<p>The CPython source tree contains <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/iOS/testbed">a testbed project</a> that
is used to run the CPython test suite on the iOS simulator. This testbed can also
be used as a testbed project for running your Python librarys test suite on iOS.</p>
<p>After building or obtaining an iOS XCFramework (See <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/iOS/README.rst">iOS/README.rst</a>
for details), create a clone of the Python iOS testbed project by running:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>python<span class="w"> </span>iOS/testbed<span class="w"> </span>clone<span class="w"> </span>--framework<span class="w"> </span>&lt;path/to/Python.xcframework&gt;<span class="w"> </span>--app<span class="w"> </span>&lt;path/to/module1&gt;<span class="w"> </span>--app<span class="w"> </span>&lt;path/to/module2&gt;<span class="w"> </span>app-testbed
</pre></div>
</div>
<p>You will need to modify the <code class="docutils literal notranslate"><span class="pre">iOS/testbed</span></code> reference to point to that
directory in the CPython source tree; any folders specified with the <code class="docutils literal notranslate"><span class="pre">--app</span></code>
flag will be copied into the cloned testbed project. The resulting testbed will
be created in the <code class="docutils literal notranslate"><span class="pre">app-testbed</span></code> folder. In this example, the <code class="docutils literal notranslate"><span class="pre">module1</span></code> and
<code class="docutils literal notranslate"><span class="pre">module2</span></code> would be importable modules at runtime. If your project has
additional dependencies, they can be installed into the
<code class="docutils literal notranslate"><span class="pre">app-testbed/iOSTestbed/app_packages</span></code> folder (using <code class="docutils literal notranslate"><span class="pre">pip</span> <span class="pre">install</span> <span class="pre">--target</span>
<span class="pre">app-testbed/iOSTestbed/app_packages</span></code> or similar).</p>
<p>You can then use the <code class="docutils literal notranslate"><span class="pre">app-testbed</span></code> folder to run the test suite for your app,
For example, if <code class="docutils literal notranslate"><span class="pre">module1.tests</span></code> was the entry point to your test suite, you
could run:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>python<span class="w"> </span>app-testbed<span class="w"> </span>run<span class="w"> </span>--<span class="w"> </span>module1.tests
</pre></div>
</div>
<p>This is the equivalent of running <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span> <span class="pre">module1.tests</span></code> on a desktop
Python build. Any arguments after the <code class="docutils literal notranslate"><span class="pre">--</span></code> will be passed to the testbed as
if they were arguments to <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">-m</span></code> on a desktop machine.</p>
<p>You can also open the testbed project in Xcode by running:</p>
<div class="highlight-bash notranslate"><div class="highlight"><pre><span></span>$<span class="w"> </span>open<span class="w"> </span>app-testbed/iOSTestbed.xcodeproj
</pre></div>
</div>
<p>This will allow you to use the full Xcode suite of tools for debugging.</p>
</section>
</section>
<section id="app-store-compliance">
<h2><span class="section-number">7.3. </span>App Store Compliance<a class="headerlink" href="#app-store-compliance" title="Link to this heading"></a></h2>
<p>The only mechanism for distributing apps to third-party iOS devices is to
submit the app to the iOS App Store; apps submitted for distribution must pass
Apples app review process. This process includes a set of automated validation
rules that inspect the submitted application bundle for problematic code.</p>
<p>The Python standard library contains some code that is known to violate these
automated rules. While these violations appear to be false positives, Apples
review rules cannot be challenged; so, it is necessary to modify the Python
standard library for an app to pass App Store review.</p>
<p>The Python source tree contains
<a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Mac/Resources/app-store-compliance.patch">a patch file</a> that will remove
all code that is known to cause issues with the App Store review process. This
patch is applied automatically when building for iOS.</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">7. Using Python on iOS</a><ul>
<li><a class="reference internal" href="#python-at-runtime-on-ios">7.1. Python at runtime on iOS</a><ul>
<li><a class="reference internal" href="#ios-version-compatibility">7.1.1. iOS version compatibility</a></li>
<li><a class="reference internal" href="#platform-identification">7.1.2. Platform identification</a></li>
<li><a class="reference internal" href="#standard-library-availability">7.1.3. Standard library availability</a></li>
<li><a class="reference internal" href="#binary-extension-modules">7.1.4. Binary extension modules</a></li>
<li><a class="reference internal" href="#compiler-stub-binaries">7.1.5. Compiler stub binaries</a></li>
</ul>
</li>
<li><a class="reference internal" href="#installing-python-on-ios">7.2. Installing Python on iOS</a><ul>
<li><a class="reference internal" href="#tools-for-building-ios-apps">7.2.1. Tools for building iOS apps</a></li>
<li><a class="reference internal" href="#adding-python-to-an-ios-project">7.2.2. Adding Python to an iOS project</a></li>
<li><a class="reference internal" href="#testing-a-python-package">7.2.3. Testing a Python package</a></li>
</ul>
</li>
<li><a class="reference internal" href="#app-store-compliance">7.3. App Store Compliance</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="android.html"
title="previous chapter"><span class="section-number">6. </span>Using Python on Android</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="editors.html"
title="next chapter"><span class="section-number">8. </span>Editors and IDEs</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/ios.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="editors.html" title="8. Editors and IDEs"
>next</a> |</li>
<li class="right" >
<a href="android.html" title="6. Using Python on Android"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">7. </span>Using Python on iOS</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@ -0,0 +1,741 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="5. Using Python on macOS" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/using/mac.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="This document aims to give an overview of macOS-specific behavior you should know about to get started with Python on Mac computers. Python on a Mac running macOS is very similar to Python on other..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="This document aims to give an overview of macOS-specific behavior you should know about to get started with Python on Mac computers. Python on a Mac running macOS is very similar to Python on other..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>5. Using Python on macOS &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="6. Using Python on Android" href="android.html" />
<link rel="prev" title="4. Using Python on Windows" href="windows.html" />
<link rel="canonical" href="https://docs.python.org/3/using/mac.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">5. Using Python on macOS</a><ul>
<li><a class="reference internal" href="#using-python-for-macos-from-python-org">5.1. Using Python for macOS from <code class="docutils literal notranslate"><span class="pre">python.org</span></code></a><ul>
<li><a class="reference internal" href="#installation-steps">5.1.1. Installation steps</a></li>
<li><a class="reference internal" href="#how-to-run-a-python-script">5.1.2. How to run a Python script</a></li>
</ul>
</li>
<li><a class="reference internal" href="#alternative-distributions">5.2. Alternative Distributions</a></li>
<li><a class="reference internal" href="#installing-additional-python-packages">5.3. Installing Additional Python Packages</a></li>
<li><a class="reference internal" href="#gui-programming">5.4. GUI Programming</a></li>
<li><a class="reference internal" href="#advanced-topics">5.5. Advanced Topics</a><ul>
<li><a class="reference internal" href="#installing-free-threaded-binaries">5.5.1. Installing Free-threaded Binaries</a></li>
<li><a class="reference internal" href="#installing-using-the-command-line">5.5.2. Installing using the command line</a></li>
<li><a class="reference internal" href="#distributing-python-applications">5.5.3. Distributing Python Applications</a></li>
<li><a class="reference internal" href="#app-store-compliance">5.5.4. App Store Compliance</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-resources">5.6. Other Resources</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="windows.html"
title="previous chapter"><span class="section-number">4. </span>Using Python on Windows</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="android.html"
title="next chapter"><span class="section-number">6. </span>Using Python on Android</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/mac.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="android.html" title="6. Using Python on Android"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="windows.html" title="4. Using Python on Windows"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">5. </span>Using Python on macOS</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="using-python-on-macos">
<span id="using-on-mac"></span><h1><span class="section-number">5. </span>Using Python on macOS<a class="headerlink" href="#using-python-on-macos" title="Link to this heading"></a></h1>
<p>This document aims to give an overview of macOS-specific behavior you should
know about to get started with Python on Mac computers.
Python on a Mac running macOS is very similar to Python on other Unix-derived platforms,
but there are some differences in installation and some features.</p>
<p>There are various ways to obtain and install Python for macOS.
Pre-built versions of the most recent versions of Python are available
from a number of distributors. Much of this document describes use of
the Pythons provided by the CPython release team for download from
the <a class="reference external" href="https://www.python.org/downloads/">python.org website</a>. See
<a class="reference internal" href="#alternative-bundles"><span class="std std-ref">Alternative Distributions</span></a> for some other options.</p>
<section id="using-python-for-macos-from-python-org">
<span id="getting-and-installing-macpython"></span><span id="getting-osx"></span><h2><span class="section-number">5.1. </span>Using Python for macOS from <code class="docutils literal notranslate"><span class="pre">python.org</span></code><a class="headerlink" href="#using-python-for-macos-from-python-org" title="Link to this heading"></a></h2>
<section id="installation-steps">
<h3><span class="section-number">5.1.1. </span>Installation steps<a class="headerlink" href="#installation-steps" title="Link to this heading"></a></h3>
<p>For <a class="reference external" href="https://www.python.org/downloads/">current Python versions</a>
(other than those in <code class="docutils literal notranslate"><span class="pre">security</span></code> status), the release team produces a
<strong>Python for macOS</strong> installer package for each new release.
A list of available installers
is available <a class="reference external" href="https://www.python.org/downloads/macos/">here</a>.
We recommend using the most recent supported Python version where possible.
Current installers provide a
<a class="reference external" href="https://en.wikipedia.org/wiki/Universal_binary">universal2 binary</a> build
of Python which runs natively on all Macs (Apple Silicon and Intel) that are
supported by a wide range of macOS versions,
currently typically from at least <strong>macOS 10.13 High Sierra</strong> on.</p>
<p>The downloaded file is a standard macOS installer package file (<code class="docutils literal notranslate"><span class="pre">.pkg</span></code>).
File integrity information (checksum, size, sigstore signature, etc) for each file is included
on the release download page. Installer packages and their contents are signed and notarized
with <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">Software</span> <span class="pre">Foundation</span></code> Apple Developer ID certificates
to meet <a class="reference external" href="https://support.apple.com/en-us/102445">macOS Gatekeeper requirements</a>.</p>
<p>For a default installation, double-click on the downloaded installer package file.
This should launch the standard macOS Installer app and display the first of several
installer windows steps.</p>
<img alt="../_images/mac_installer_01_introduction.png" src="../_images/mac_installer_01_introduction.png" />
<p>Clicking on the <strong>Continue</strong> button brings up the <strong>Read Me</strong> for this installer.
Besides other important information, the <strong>Read Me</strong> documents which Python version is
going to be installed and on what versions of macOS it is supported. You may need
to scroll through to read the whole file. By default, this <strong>Read Me</strong> will also be
installed in <code class="docutils literal notranslate"><span class="pre">/Applications/Python</span> <span class="pre">3.13/</span></code> and available to read anytime.</p>
<img alt="../_images/mac_installer_02_readme.png" src="../_images/mac_installer_02_readme.png" />
<p>Clicking on <strong>Continue</strong> proceeds to display the license for Python and for
other included software. You will then need to <strong>Agree</strong> to the license terms
before proceeding to the next step. This license file will also be installed
and available to be read later.</p>
<img alt="../_images/mac_installer_03_license.png" src="../_images/mac_installer_03_license.png" />
<p>After the license terms are accepted, the next step is the <strong>Installation Type</strong>
display. For most uses, the standard set of installation operations is appropriate.</p>
<img alt="../_images/mac_installer_04_installation_type.png" src="../_images/mac_installer_04_installation_type.png" />
<p>By pressing the <strong>Customize</strong> button, you can choose to omit or select certain package
components of the installer. Click on each package name to see a description of
what it installs.
To also install support for the optional experimental free-threaded feature,
see <a class="reference internal" href="#install-freethreaded-macos"><span class="std std-ref">Installing Free-threaded Binaries</span></a>.</p>
<img alt="../_images/mac_installer_05_custom_install.png" src="../_images/mac_installer_05_custom_install.png" />
<p>In either case, clicking <strong>Install</strong> will begin the install process by asking
permission to install new software. A macOS user name with <code class="docutils literal notranslate"><span class="pre">Administrator</span></code> privilege
is needed as the installed Python will be available to all users of the Mac.</p>
<p>When the installation is complete, the <strong>Summary</strong> window will appear.</p>
<img alt="../_images/mac_installer_06_summary.png" src="../_images/mac_installer_06_summary.png" />
<p>Double-click on the <strong class="command">Install Certificates.command</strong>
icon or file in the <code class="docutils literal notranslate"><span class="pre">/Applications/Python</span> <span class="pre">3.13/</span></code> window to complete the
installation.</p>
<img alt="../_images/mac_installer_07_applications.png" src="../_images/mac_installer_07_applications.png" />
<p>This will open a temporary <strong class="program">Terminal</strong> shell window that
will use the new Python to download and install SSL root certificates
for its use.</p>
<img alt="../_images/mac_installer_08_install_certificates.png" src="../_images/mac_installer_08_install_certificates.png" />
<p>If <code class="docutils literal notranslate"><span class="pre">Successfully</span> <span class="pre">installed</span> <span class="pre">certifi</span></code> and <code class="docutils literal notranslate"><span class="pre">update</span> <span class="pre">complete</span></code> appears
in the terminal window, the installation is complete.
Close this terminal window and the installer window.</p>
<p>A default install will include:</p>
<ul class="simple">
<li><p>A <code class="docutils literal notranslate"><span class="pre">Python</span> <span class="pre">3.13</span></code> folder in your <code class="file docutils literal notranslate"><span class="pre">Applications</span></code> folder. In here
you find <strong class="program">IDLE</strong>, the development environment that is a standard part of official
Python distributions; and <strong class="program">Python Launcher</strong>, which handles double-clicking Python
scripts from the macOS <a class="reference external" href="https://support.apple.com/en-us/HT201732">Finder</a>.</p></li>
<li><p>A framework <code class="file docutils literal notranslate"><span class="pre">/Library/Frameworks/Python.framework</span></code>, which includes the
Python executable and libraries. The installer adds this location to your shell
path. To uninstall Python, you can remove these three things.
Symlinks to the Python executable are placed in <code class="file docutils literal notranslate"><span class="pre">/usr/local/bin/</span></code>.</p></li>
</ul>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Recent versions of macOS include a <strong class="command">python3</strong> command in <code class="file docutils literal notranslate"><span class="pre">/usr/bin/python3</span></code>
that links to a usually older and incomplete version of Python provided by and for use by
the Apple development tools, <strong class="program">Xcode</strong> or the <strong class="program">Command Line Tools for Xcode</strong>.
You should never modify or attempt to delete this installation, as it is
Apple-controlled and is used by Apple-provided or third-party software. If
you choose to install a newer Python version from <code class="docutils literal notranslate"><span class="pre">python.org</span></code>, you will have
two different but functional Python installations on your computer that
can co-exist. The default installer options should ensure that its <strong class="command">python3</strong>
will be used instead of the system <strong class="command">python3</strong>.</p>
</div>
</section>
<section id="how-to-run-a-python-script">
<h3><span class="section-number">5.1.2. </span>How to run a Python script<a class="headerlink" href="#how-to-run-a-python-script" title="Link to this heading"></a></h3>
<p>There are two ways to invoke the Python interpreter.
If you are familiar with using a Unix shell in a terminal
window, you can invoke <code class="docutils literal notranslate"><span class="pre">python3.13</span></code> or <code class="docutils literal notranslate"><span class="pre">python3</span></code> optionally
followed by one or more command line options (described in <a class="reference internal" href="cmdline.html#using-on-general"><span class="std std-ref">Command line and environment</span></a>).
The Python tutorial also has a useful section on
<a class="reference internal" href="../tutorial/appendix.html#tut-interac"><span class="std std-ref">using Python interactively from a shell</span></a>.</p>
<p>You can also invoke the interpreter through an integrated
development environment.
<a class="reference internal" href="../library/idle.html#idle"><span class="std std-ref">IDLE — Python editor and shell</span></a> is a basic editor and interpreter environment
which is included with the standard distribution of Python.
<strong class="program">IDLE</strong> includes a Help menu that allows you to access Python documentation. If you
are completely new to Python, you can read the tutorial introduction
in that document.</p>
<p>There are many other editors and IDEs available, see <a class="reference internal" href="editors.html#editors"><span class="std std-ref">Editors and IDEs</span></a>
for more information.</p>
<p>To run a Python script file from the terminal window, you can
invoke the interpreter with the name of the script file:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">python3.13</span></code> <code class="docutils literal notranslate"><span class="pre">myscript.py</span></code></p>
</div></blockquote>
<p>To run your script from the Finder, you can either:</p>
<ul class="simple">
<li><p>Drag it to <strong class="program">Python Launcher</strong>.</p></li>
<li><p>Select <strong class="program">Python Launcher</strong> as the default application to open your
script (or any <code class="docutils literal notranslate"><span class="pre">.py</span></code> script) through the Finder Info window and double-click it.
<strong class="program">Python Launcher</strong> has various preferences to control how your script is
launched. Option-dragging allows you to change these for one invocation, or use
its <code class="docutils literal notranslate"><span class="pre">Preferences</span></code> menu to change things globally.</p></li>
</ul>
<p>Be aware that running the script directly from the macOS Finder might
produce different results than when running from a terminal window as
the script will not be run in the usual shell environment including
any setting of environment variables in shell profiles.
And, as with any other script or program,
be certain of what you are about to run.</p>
</section>
</section>
<section id="alternative-distributions">
<span id="alternative-bundles"></span><h2><span class="section-number">5.2. </span>Alternative Distributions<a class="headerlink" href="#alternative-distributions" title="Link to this heading"></a></h2>
<p>Besides the standard <code class="docutils literal notranslate"><span class="pre">python.org</span></code> for macOS installer, there are third-party
distributions for macOS that may include additional functionality.
Some popular distributions and their key features:</p>
<dl class="simple">
<dt><a class="reference external" href="https://www.activestate.com/products/python/">ActivePython</a></dt><dd><p>Installer with multi-platform compatibility, documentation</p>
</dd>
<dt><a class="reference external" href="https://www.anaconda.com/download/">Anaconda</a></dt><dd><p>Popular scientific modules (such as numpy, scipy, and pandas) and the
<code class="docutils literal notranslate"><span class="pre">conda</span></code> package manager.</p>
</dd>
<dt><a class="reference external" href="https://brew.sh">Homebrew</a></dt><dd><p>Package manager for macOS including multiple versions of Python and many
third-party Python-based packages (including numpy, scipy, and pandas).</p>
</dd>
<dt><a class="reference external" href="https://www.macports.org">MacPorts</a></dt><dd><p>Another package manager for macOS including multiple versions of Python and many
third-party Python-based packages. May include pre-built versions of Python and
many packages for older versions of macOS.</p>
</dd>
</dl>
<p>Note that distributions might not include the latest versions of Python or
other libraries, and are not maintained or supported by the core Python team.</p>
</section>
<section id="installing-additional-python-packages">
<span id="mac-package-manager"></span><h2><span class="section-number">5.3. </span>Installing Additional Python Packages<a class="headerlink" href="#installing-additional-python-packages" title="Link to this heading"></a></h2>
<p>Refer to the <a class="reference external" href="https://packaging.python.org/en/latest/tutorials/installing-packages/">Python Packaging User Guide</a> for more information.</p>
</section>
<section id="gui-programming">
<span id="gui-programming-on-the-mac"></span><span id="osx-gui-scripts"></span><h2><span class="section-number">5.4. </span>GUI Programming<a class="headerlink" href="#gui-programming" title="Link to this heading"></a></h2>
<p>There are several options for building GUI applications on the Mac with Python.</p>
<p>The standard Python GUI toolkit is <a class="reference internal" href="../library/tkinter.html#module-tkinter" title="tkinter: Interface to Tcl/Tk for graphical user interfaces"><code class="xref py py-mod docutils literal notranslate"><span class="pre">tkinter</span></code></a>, based on the cross-platform
Tk toolkit (<a class="reference external" href="https://www.tcl.tk">https://www.tcl.tk</a>). A macOS-native version of Tk is included with
the installer.</p>
<p><em>PyObjC</em> is a Python binding to Apples Objective-C/Cocoa framework.
Information on PyObjC is available from <a class="extlink-pypi reference external" href="https://pypi.org/project/pyobjc/">pyobjc</a>.</p>
<p>A number of alternative macOS GUI toolkits are available including:</p>
<ul class="simple">
<li><p><a class="reference external" href="https://www.qt.io/qt-for-python">PySide</a>: Official Python bindings to the
<a class="reference external" href="https://wiki.qt.io/Qt_for_Python">Qt GUI toolkit</a>.</p></li>
<li><p><a class="reference external" href="https://riverbankcomputing.com/software/pyqt/">PyQt</a>: Alternative
Python bindings to Qt.</p></li>
<li><p><a class="reference external" href="https://kivy.org">Kivy</a>: A cross-platform GUI toolkit that supports
desktop and mobile platforms.</p></li>
<li><p><a class="reference external" href="https://toga.readthedocs.io">Toga</a>: Part of the <a class="reference external" href="https://beeware.org">BeeWare Project</a>; supports desktop, mobile, web and console apps.</p></li>
<li><p><a class="reference external" href="https://wxpython.org">wxPython</a>: A cross-platform toolkit that
supports desktop operating systems.</p></li>
</ul>
</section>
<section id="advanced-topics">
<h2><span class="section-number">5.5. </span>Advanced Topics<a class="headerlink" href="#advanced-topics" title="Link to this heading"></a></h2>
<section id="installing-free-threaded-binaries">
<span id="install-freethreaded-macos"></span><h3><span class="section-number">5.5.1. </span>Installing Free-threaded Binaries<a class="headerlink" href="#installing-free-threaded-binaries" title="Link to this heading"></a></h3>
<div class="versionadded">
<p><span class="versionmodified added">Added in version 3.13: </span>(Experimental)</p>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Everything described in this section is considered experimental,
and should be expected to change in future releases.</p>
</div>
<p>The <code class="docutils literal notranslate"><span class="pre">python.org</span></code> <a class="reference internal" href="#getting-and-installing-macpython"><span class="std std-ref">Python for macOS</span></a>
installer package can optionally install an additional build of
Python 3.13 that supports <span class="target" id="index-0"></span><a class="pep reference external" href="https://peps.python.org/pep-0703/"><strong>PEP 703</strong></a>, the experimental free-threading feature
(running with the <a class="reference internal" href="../glossary.html#term-global-interpreter-lock"><span class="xref std std-term">global interpreter lock</span></a> disabled).
Check the release page on <code class="docutils literal notranslate"><span class="pre">python.org</span></code> for possible updated information.</p>
<p>Because this feature is still considered experimental, the support for it
is not installed by default. It is packaged as a separate install option,
available by clicking the <strong>Customize</strong> button on the <strong>Installation Type</strong>
step of the installer as described above.</p>
<img alt="../_images/mac_installer_09_custom_install_free_threaded.png" src="../_images/mac_installer_09_custom_install_free_threaded.png" />
<p>If the box next to the <strong>Free-threaded Python</strong> package name is checked,
a separate <code class="file docutils literal notranslate"><span class="pre">PythonT.framework</span></code> will also be installed
alongside the normal <code class="file docutils literal notranslate"><span class="pre">Python.framework</span></code> in <code class="file docutils literal notranslate"><span class="pre">/Library/Frameworks</span></code>.
This configuration allows a free-threaded Python 3.13 build to co-exist
on your system with a traditional (GIL only) Python 3.13 build with
minimal risk while installing or testing. This installation layout is itself
experimental and is subject to change in future releases.</p>
<p>Known cautions and limitations:</p>
<ul>
<li><p>The <strong>UNIX command-line tools</strong> package, which is selected by default,
will install links in <code class="file docutils literal notranslate"><span class="pre">/usr/local/bin</span></code> for <code class="docutils literal notranslate"><span class="pre">python3.13t</span></code>,
the free-threaded interpreter, and <code class="docutils literal notranslate"><span class="pre">python3.13t-config</span></code>,
a configuration utility which may be useful for package builders.
Since <code class="file docutils literal notranslate"><span class="pre">/usr/local/bin</span></code> is typically included in your shell <code class="docutils literal notranslate"><span class="pre">PATH</span></code>,
in most cases no changes to your <code class="docutils literal notranslate"><span class="pre">PATH</span></code> environment variables should
be needed to use <code class="docutils literal notranslate"><span class="pre">python3.13t</span></code>.</p></li>
<li><p>For this release, the <strong>Shell profile updater</strong> package and the
<code class="file docutils literal notranslate"><span class="pre">Update</span> <span class="pre">Shell</span> <span class="pre">Profile.command</span></code> in <code class="docutils literal notranslate"><span class="pre">/Applications/Python</span> <span class="pre">3.13/</span></code>
do not support the free-threaded package.</p></li>
<li><p>The free-threaded build and the traditional build have separate search
paths and separate <code class="file docutils literal notranslate"><span class="pre">site-packages</span></code> directories so, by default,
if you need a package available in both builds, it may need to be installed in both.
The free-threaded package will install a separate instance of <strong class="program">pip</strong> for use
with <code class="docutils literal notranslate"><span class="pre">python3.13t</span></code>.</p>
<ul>
<li><p>To install a package using <strong class="command">pip</strong> without a <strong class="command">venv</strong>:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">python3.13t</span></code> <code class="docutils literal notranslate"><span class="pre">-m</span> <span class="pre">pip</span> <span class="pre">install</span> <span class="pre">&lt;package_name&gt;</span></code></p>
</div></blockquote>
</li>
</ul>
</li>
<li><p>When working with multiple Python environments, it is usually safest and easiest
to <a class="reference internal" href="../tutorial/venv.html#tut-venv"><span class="std std-ref">create and use virtual environments</span></a>.
This can avoid possible command name conflicts and confusion about which Python is in use:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">python3.13t</span></code> <code class="docutils literal notranslate"><span class="pre">-m</span> <span class="pre">venv</span> <span class="pre">&lt;venv_name&gt;</span></code></p>
</div></blockquote>
<p>then <strong class="command">activate</strong>.</p>
</li>
<li><p>To run a free-threaded version of IDLE:</p>
<blockquote>
<div><p><code class="docutils literal notranslate"><span class="pre">python3.13t</span></code> <code class="docutils literal notranslate"><span class="pre">-m</span> <span class="pre">idlelib</span></code></p>
</div></blockquote>
</li>
<li><p>The interpreters in both builds respond to the same
<a class="reference internal" href="cmdline.html#using-on-envvars"><span class="std std-ref">PYTHON environment variables</span></a>
which may have unexpected results, for example, if you have <code class="docutils literal notranslate"><span class="pre">PYTHONPATH</span></code>
set in a shell profile. If necessary, there are
<a class="reference internal" href="cmdline.html#using-on-interface-options"><span class="std std-ref">command line options</span></a> like <code class="docutils literal notranslate"><span class="pre">-E</span></code>
to ignore these environment variables.</p></li>
<li><p>The free-threaded build links to the third-party shared libraries,
such as <code class="docutils literal notranslate"><span class="pre">OpenSSL</span></code> and <code class="docutils literal notranslate"><span class="pre">Tk</span></code>, installed in the traditional framework.
This means that both builds also share one set of trust certificates
as installed by the <strong class="command">Install Certificates.command</strong> script,
thus it only needs to be run once.</p></li>
<li><p>If you cannot depend on the link in <code class="docutils literal notranslate"><span class="pre">/usr/local/bin</span></code> pointing to the
<code class="docutils literal notranslate"><span class="pre">python.org</span></code> free-threaded <code class="docutils literal notranslate"><span class="pre">python3.13t</span></code> (for example, if you want
to install your own version there or some other distribution does),
you can explicitly set your shell <code class="docutils literal notranslate"><span class="pre">PATH</span></code> environment variable to
include the <code class="docutils literal notranslate"><span class="pre">PythonT</span></code> framework <code class="docutils literal notranslate"><span class="pre">bin</span></code> directory:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nb">export</span><span class="w"> </span><span class="nv">PATH</span><span class="o">=</span><span class="s2">&quot;/Library/Frameworks/PythonT.framework/Versions/3.13/bin&quot;</span>:<span class="s2">&quot;</span><span class="nv">$PATH</span><span class="s2">&quot;</span>
</pre></div>
</div>
<p>The traditional framework installation by default does something similar,
except for <code class="file docutils literal notranslate"><span class="pre">Python.framework</span></code>. Be aware that having both framework <code class="docutils literal notranslate"><span class="pre">bin</span></code>
directories in <code class="docutils literal notranslate"><span class="pre">PATH</span></code> can lead to confusion if there are duplicate names
like <code class="docutils literal notranslate"><span class="pre">python3.13</span></code> in both; which one is actually used depends on the order
they appear in <code class="docutils literal notranslate"><span class="pre">PATH</span></code>. The <code class="docutils literal notranslate"><span class="pre">which</span> <span class="pre">python3.x</span></code> or <code class="docutils literal notranslate"><span class="pre">which</span> <span class="pre">python3.xt</span></code>
commands can show which path is being used. Using virtual environments
can help avoid such ambiguities. Another option might be to create
a shell <strong class="command">alias</strong> to the desired interpreter, like:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nb">alias</span><span class="w"> </span>py3.13<span class="o">=</span><span class="s2">&quot;/Library/Frameworks/Python.framework/Versions/3.13/bin/python3.13&quot;</span>
<span class="nb">alias</span><span class="w"> </span>py3.13t<span class="o">=</span><span class="s2">&quot;/Library/Frameworks/PythonT.framework/Versions/3.13/bin/python3.13t&quot;</span>
</pre></div>
</div>
</li>
</ul>
</section>
<section id="installing-using-the-command-line">
<h3><span class="section-number">5.5.2. </span>Installing using the command line<a class="headerlink" href="#installing-using-the-command-line" title="Link to this heading"></a></h3>
<p>If you want to use automation to install the <code class="docutils literal notranslate"><span class="pre">python.org</span></code> installer package
(rather than by using the familiar macOS <strong class="program">Installer</strong> GUI app),
the macOS command line <strong class="command">installer</strong> utility lets you select non-default
options, too. If you are not familiar with <strong class="command">installer</strong>, it can be
somewhat cryptic (see <strong class="command">man installer</strong> for more information).
As an example, the following shell snippet shows one way to do it,
using the <code class="docutils literal notranslate"><span class="pre">3.13.0b2</span></code> release and selecting the free-threaded interpreter
option:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="nv">RELEASE</span><span class="o">=</span><span class="s2">&quot;python-3.13.0b2-macos11.pkg&quot;</span>
<span class="c1"># download installer pkg</span>
curl<span class="w"> </span>-O<span class="w"> </span>https://www.python.org/ftp/python/3.13.0/<span class="si">${</span><span class="nv">RELEASE</span><span class="si">}</span>
<span class="c1"># create installer choicechanges to customize the install:</span>
<span class="c1"># enable the PythonTFramework-3.13 package</span>
<span class="c1"># while accepting the other defaults (install all other packages)</span>
cat<span class="w"> </span>&gt;<span class="w"> </span>./choicechanges.plist<span class="w"> </span><span class="s">&lt;&lt;EOF</span>
<span class="s">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span>
<span class="s">&lt;!DOCTYPE plist PUBLIC &quot;-//Apple//DTD PLIST 1.0//EN&quot; &quot;http://www.apple.com/DTDs/PropertyList-1.0.dtd&quot;&gt;</span>
<span class="s">&lt;plist version=&quot;1.0&quot;&gt;</span>
<span class="s">&lt;array&gt;</span>
<span class="s"> &lt;dict&gt;</span>
<span class="s"> &lt;key&gt;attributeSetting&lt;/key&gt;</span>
<span class="s"> &lt;integer&gt;1&lt;/integer&gt;</span>
<span class="s"> &lt;key&gt;choiceAttribute&lt;/key&gt;</span>
<span class="s"> &lt;string&gt;selected&lt;/string&gt;</span>
<span class="s"> &lt;key&gt;choiceIdentifier&lt;/key&gt;</span>
<span class="s"> &lt;string&gt;org.python.Python.PythonTFramework-3.13&lt;/string&gt;</span>
<span class="s"> &lt;/dict&gt;</span>
<span class="s">&lt;/array&gt;</span>
<span class="s">&lt;/plist&gt;</span>
<span class="s">EOF</span>
sudo<span class="w"> </span>installer<span class="w"> </span>-pkg<span class="w"> </span>./<span class="si">${</span><span class="nv">RELEASE</span><span class="si">}</span><span class="w"> </span>-applyChoiceChangesXML<span class="w"> </span>./choicechanges.plist<span class="w"> </span>-target<span class="w"> </span>/
</pre></div>
</div>
<p>You can then test that both installer builds are now available with something like:</p>
<div class="highlight-console notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span><span class="c1"># test that the free-threaded interpreter was installed if the Unix Command Tools package was enabled</span>
<span class="gp">$ </span>/usr/local/bin/python3.13t<span class="w"> </span>-VV
<span class="go">Python 3.13.0b2 experimental free-threading build (v3.13.0b2:3a83b172af, Jun 5 2024, 12:57:31) [Clang 15.0.0 (clang-1500.3.9.4)]</span>
<span class="gp">$ </span><span class="c1"># and the traditional interpreter</span>
<span class="gp">$ </span>/usr/local/bin/python3.13<span class="w"> </span>-VV
<span class="go">Python 3.13.0b2 (v3.13.0b2:3a83b172af, Jun 5 2024, 12:50:24) [Clang 15.0.0 (clang-1500.3.9.4)]</span>
<span class="gp">$ </span><span class="c1"># test that they are also available without the prefix if /usr/local/bin is on $PATH</span>
<span class="gp">$ </span>python3.13t<span class="w"> </span>-VV
<span class="go">Python 3.13.0b2 experimental free-threading build (v3.13.0b2:3a83b172af, Jun 5 2024, 12:57:31) [Clang 15.0.0 (clang-1500.3.9.4)]</span>
<span class="gp">$ </span>python3.13<span class="w"> </span>-VV
<span class="go">Python 3.13.0b2 (v3.13.0b2:3a83b172af, Jun 5 2024, 12:50:24) [Clang 15.0.0 (clang-1500.3.9.4)]</span>
</pre></div>
</div>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Current <code class="docutils literal notranslate"><span class="pre">python.org</span></code> installers only install to fixed locations like
<code class="file docutils literal notranslate"><span class="pre">/Library/Frameworks/</span></code>, <code class="file docutils literal notranslate"><span class="pre">/Applications</span></code>, and <code class="file docutils literal notranslate"><span class="pre">/usr/local/bin</span></code>.
You cannot use the <strong class="command">installer</strong> <code class="docutils literal notranslate"><span class="pre">-domain</span></code> option to install to
other locations.</p>
</div>
</section>
<section id="distributing-python-applications">
<span id="distributing-python-applications-on-the-mac"></span><h3><span class="section-number">5.5.3. </span>Distributing Python Applications<a class="headerlink" href="#distributing-python-applications" title="Link to this heading"></a></h3>
<p>A range of tools exist for converting your Python code into a standalone
distributable application:</p>
<ul class="simple">
<li><p><a class="extlink-pypi reference external" href="https://pypi.org/project/py2app/">py2app</a>: Supports creating macOS <code class="docutils literal notranslate"><span class="pre">.app</span></code>
bundles from a Python project.</p></li>
<li><p><a class="reference external" href="https://briefcase.readthedocs.io">Briefcase</a>: Part of the <a class="reference external" href="https://beeware.org">BeeWare Project</a>; a cross-platform packaging tool that supports
creation of <code class="docutils literal notranslate"><span class="pre">.app</span></code> bundles on macOS, as well as managing signing and
notarization.</p></li>
<li><p><a class="reference external" href="https://pyinstaller.org/">PyInstaller</a>: A cross-platform packaging tool that creates
a single file or folder as a distributable artifact.</p></li>
</ul>
</section>
<section id="app-store-compliance">
<h3><span class="section-number">5.5.4. </span>App Store Compliance<a class="headerlink" href="#app-store-compliance" title="Link to this heading"></a></h3>
<p>Apps submitted for distribution through the macOS App Store must pass Apples
app review process. This process includes a set of automated validation rules
that inspect the submitted application bundle for problematic code.</p>
<p>The Python standard library contains some code that is known to violate these
automated rules. While these violations appear to be false positives, Apples
review rules cannot be challenged. Therefore, it is necessary to modify the
Python standard library for an app to pass App Store review.</p>
<p>The Python source tree contains
<a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/Mac/Resources/app-store-compliance.patch">a patch file</a> that will remove
all code that is known to cause issues with the App Store review process. This
patch is applied automatically when CPython is configured with the
<a class="reference internal" href="configure.html#cmdoption-with-app-store-compliance"><code class="xref std std-option docutils literal notranslate"><span class="pre">--with-app-store-compliance</span></code></a> option.</p>
<p>This patch is not normally required to use CPython on a Mac; nor is it required
if you are distributing an app <em>outside</em> the macOS App Store. It is <em>only</em>
required if you are using the macOS App Store as a distribution channel.</p>
</section>
</section>
<section id="other-resources">
<h2><span class="section-number">5.6. </span>Other Resources<a class="headerlink" href="#other-resources" title="Link to this heading"></a></h2>
<p>The <a class="reference external" href="https://www.python.org/about/help/">python.org Help page</a> has links to many useful resources.
The <a class="reference external" href="https://www.python.org/community/sigs/current/pythonmac-sig/">Pythonmac-SIG mailing list</a>
is another support resource specifically for Python users and developers on the Mac.</p>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">5. Using Python on macOS</a><ul>
<li><a class="reference internal" href="#using-python-for-macos-from-python-org">5.1. Using Python for macOS from <code class="docutils literal notranslate"><span class="pre">python.org</span></code></a><ul>
<li><a class="reference internal" href="#installation-steps">5.1.1. Installation steps</a></li>
<li><a class="reference internal" href="#how-to-run-a-python-script">5.1.2. How to run a Python script</a></li>
</ul>
</li>
<li><a class="reference internal" href="#alternative-distributions">5.2. Alternative Distributions</a></li>
<li><a class="reference internal" href="#installing-additional-python-packages">5.3. Installing Additional Python Packages</a></li>
<li><a class="reference internal" href="#gui-programming">5.4. GUI Programming</a></li>
<li><a class="reference internal" href="#advanced-topics">5.5. Advanced Topics</a><ul>
<li><a class="reference internal" href="#installing-free-threaded-binaries">5.5.1. Installing Free-threaded Binaries</a></li>
<li><a class="reference internal" href="#installing-using-the-command-line">5.5.2. Installing using the command line</a></li>
<li><a class="reference internal" href="#distributing-python-applications">5.5.3. Distributing Python Applications</a></li>
<li><a class="reference internal" href="#app-store-compliance">5.5.4. App Store Compliance</a></li>
</ul>
</li>
<li><a class="reference internal" href="#other-resources">5.6. Other Resources</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="windows.html"
title="previous chapter"><span class="section-number">4. </span>Using Python on Windows</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="android.html"
title="next chapter"><span class="section-number">6. </span>Using Python on Android</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/mac.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="android.html" title="6. Using Python on Android"
>next</a> |</li>
<li class="right" >
<a href="windows.html" title="4. Using Python on Windows"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">5. </span>Using Python on macOS</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

View File

@ -0,0 +1,548 @@
<!DOCTYPE html>
<html lang="en" data-content_root="../">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
<meta property="og:title" content="2. Using Python on Unix platforms" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://docs.python.org/3/using/unix.html" />
<meta property="og:site_name" content="Python documentation" />
<meta property="og:description" content="Getting and installing the latest version of Python: On Linux: Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features..." />
<meta property="og:image" content="https://docs.python.org/3/_static/og-image.png" />
<meta property="og:image:alt" content="Python documentation" />
<meta name="description" content="Getting and installing the latest version of Python: On Linux: Python comes preinstalled on most Linux distributions, and is available as a package on all others. However there are certain features..." />
<meta property="og:image:width" content="200">
<meta property="og:image:height" content="200">
<meta name="theme-color" content="#3776ab">
<title>2. Using Python on Unix platforms &#8212; Python 3.13.3 documentation</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=b86133f3" />
<link rel="stylesheet" type="text/css" href="../_static/pydoctheme.css?v=23252803" />
<link id="pygments_dark_css" media="(prefers-color-scheme: dark)" rel="stylesheet" type="text/css" href="../_static/pygments_dark.css?v=5349f25f" />
<script src="../_static/documentation_options.js?v=5d57ca2d"></script>
<script src="../_static/doctools.js?v=9bcbadda"></script>
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="Search within Python 3.13.3 documentation"
href="../_static/opensearch.xml"/>
<link rel="author" title="About these documents" href="../about.html" />
<link rel="index" title="Index" href="../genindex.html" />
<link rel="search" title="Search" href="../search.html" />
<link rel="copyright" title="Copyright" href="../copyright.html" />
<link rel="next" title="3. Configure Python" href="configure.html" />
<link rel="prev" title="1. Command line and environment" href="cmdline.html" />
<link rel="canonical" href="https://docs.python.org/3/using/unix.html">
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<link rel="stylesheet" href="../_static/pydoctheme_dark.css" media="(prefers-color-scheme: dark)" id="pydoctheme_dark_css">
<link rel="shortcut icon" type="image/png" href="../_static/py.svg" />
<script type="text/javascript" src="../_static/copybutton.js"></script>
<script type="text/javascript" src="../_static/menu.js"></script>
<script type="text/javascript" src="../_static/search-focus.js"></script>
<script type="text/javascript" src="../_static/themetoggle.js"></script>
<script type="text/javascript" src="../_static/rtd_switcher.js"></script>
<meta name="readthedocs-addons-api-version" content="1">
</head>
<body>
<div class="mobile-nav">
<input type="checkbox" id="menuToggler" class="toggler__input" aria-controls="navigation"
aria-pressed="false" aria-expanded="false" role="button" aria-label="Menu" />
<nav class="nav-content" role="navigation">
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<span class="nav-items-wrapper">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Python logo"/>
</a>
<span class="version_switcher_placeholder"></span>
<form role="search" class="search" action="../search.html" method="get">
<svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" class="search-icon">
<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>
</svg>
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" />
<input type="submit" value="Go"/>
</form>
</span>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label>
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">2. Using Python on Unix platforms</a><ul>
<li><a class="reference internal" href="#getting-and-installing-the-latest-version-of-python">2.1. Getting and installing the latest version of Python</a><ul>
<li><a class="reference internal" href="#on-linux">2.1.1. On Linux</a><ul>
<li><a class="reference internal" href="#installing-idle">2.1.1.1. Installing IDLE</a></li>
</ul>
</li>
<li><a class="reference internal" href="#on-freebsd-and-openbsd">2.1.2. On FreeBSD and OpenBSD</a></li>
</ul>
</li>
<li><a class="reference internal" href="#building-python">2.2. Building Python</a></li>
<li><a class="reference internal" href="#python-related-paths-and-files">2.3. Python-related paths and files</a></li>
<li><a class="reference internal" href="#miscellaneous">2.4. Miscellaneous</a></li>
<li><a class="reference internal" href="#custom-openssl">2.5. Custom OpenSSL</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="cmdline.html"
title="previous chapter"><span class="section-number">1. </span>Command line and environment</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="configure.html"
title="next chapter"><span class="section-number">3. </span>Configure Python</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/unix.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
accesskey="I">index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="configure.html" title="3. Configure Python"
accesskey="N">next</a> |</li>
<li class="right" >
<a href="cmdline.html" title="1. Command line and environment"
accesskey="P">previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>Using Python on Unix platforms</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="using-python-on-unix-platforms">
<span id="using-on-unix"></span><h1><span class="section-number">2. </span>Using Python on Unix platforms<a class="headerlink" href="#using-python-on-unix-platforms" title="Link to this heading"></a></h1>
<section id="getting-and-installing-the-latest-version-of-python">
<h2><span class="section-number">2.1. </span>Getting and installing the latest version of Python<a class="headerlink" href="#getting-and-installing-the-latest-version-of-python" title="Link to this heading"></a></h2>
<section id="on-linux">
<h3><span class="section-number">2.1.1. </span>On Linux<a class="headerlink" href="#on-linux" title="Link to this heading"></a></h3>
<p>Python comes preinstalled on most Linux distributions, and is available as a
package on all others. However there are certain features you might want to use
that are not available on your distros package. You can compile the
latest version of Python from source.</p>
<p>In the event that the latest version of Python doesnt come preinstalled and isnt
in the repositories as well, you can make packages for your own distro. Have a
look at the following links:</p>
<div class="admonition seealso">
<p class="admonition-title">See also</p>
<dl class="simple">
<dt><a class="reference external" href="https://www.debian.org/doc/manuals/maint-guide/first.en.html">https://www.debian.org/doc/manuals/maint-guide/first.en.html</a></dt><dd><p>for Debian users</p>
</dd>
<dt><a class="reference external" href="https://en.opensuse.org/Portal:Packaging">https://en.opensuse.org/Portal:Packaging</a></dt><dd><p>for OpenSuse users</p>
</dd>
<dt><a class="reference external" href="https://docs.fedoraproject.org/en-US/package-maintainers/Packaging_Tutorial_GNU_Hello/">https://docs.fedoraproject.org/en-US/package-maintainers/Packaging_Tutorial_GNU_Hello/</a></dt><dd><p>for Fedora users</p>
</dd>
<dt><a class="reference external" href="https://slackbook.org/html/package-management-making-packages.html">https://slackbook.org/html/package-management-making-packages.html</a></dt><dd><p>for Slackware users</p>
</dd>
</dl>
</div>
<section id="installing-idle">
<span id="installing-idle-on-linux"></span><h4><span class="section-number">2.1.1.1. </span>Installing IDLE<a class="headerlink" href="#installing-idle" title="Link to this heading"></a></h4>
<p>In some cases, IDLE might not be included in your Python installation.</p>
<ul>
<li><p>For Debian and Ubuntu users:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>apt<span class="w"> </span>update
sudo<span class="w"> </span>apt<span class="w"> </span>install<span class="w"> </span>idle
</pre></div>
</div>
</li>
<li><p>For Fedora, RHEL, and CentOS users:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>dnf<span class="w"> </span>install<span class="w"> </span>python3-idle
</pre></div>
</div>
</li>
<li><p>For SUSE and OpenSUSE users:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>zypper<span class="w"> </span>install<span class="w"> </span>python3-idle
</pre></div>
</div>
</li>
<li><p>For Alpine Linux users:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>sudo<span class="w"> </span>apk<span class="w"> </span>add<span class="w"> </span>python3-idle
</pre></div>
</div>
</li>
</ul>
</section>
</section>
<section id="on-freebsd-and-openbsd">
<h3><span class="section-number">2.1.2. </span>On FreeBSD and OpenBSD<a class="headerlink" href="#on-freebsd-and-openbsd" title="Link to this heading"></a></h3>
<ul>
<li><p>FreeBSD users, to add the package use:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>pkg<span class="w"> </span>install<span class="w"> </span>python3
</pre></div>
</div>
</li>
<li><p>OpenBSD users, to add the package use:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>pkg_add<span class="w"> </span>-r<span class="w"> </span>python
pkg_add<span class="w"> </span>ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/&lt;insert<span class="w"> </span>your<span class="w"> </span>architecture<span class="w"> </span>here&gt;/python-&lt;version&gt;.tgz
</pre></div>
</div>
<p>For example i386 users get the 2.5.1 version of Python using:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>pkg_add<span class="w"> </span>ftp://ftp.openbsd.org/pub/OpenBSD/4.2/packages/i386/python-2.5.1p2.tgz
</pre></div>
</div>
</li>
</ul>
</section>
</section>
<section id="building-python">
<span id="building-python-on-unix"></span><h2><span class="section-number">2.2. </span>Building Python<a class="headerlink" href="#building-python" title="Link to this heading"></a></h2>
<p>If you want to compile CPython yourself, first thing you should do is get the
<a class="reference external" href="https://www.python.org/downloads/source/">source</a>. You can download either the
latest releases source or just grab a fresh <a class="reference external" href="https://devguide.python.org/setup/#get-the-source-code">clone</a>. (If you want
to contribute patches, you will need a clone.)</p>
<p>The build process consists of the usual commands:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>./configure
make
make<span class="w"> </span>install
</pre></div>
</div>
<p><a class="reference internal" href="configure.html#configure-options"><span class="std std-ref">Configuration options</span></a> and caveats for specific Unix
platforms are extensively documented in the <a class="extlink-source reference external" href="https://github.com/python/cpython/tree/3.13/README.rst">README.rst</a> file in the
root of the Python source tree.</p>
<div class="admonition warning">
<p class="admonition-title">Warning</p>
<p><code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code> can overwrite or masquerade the <code class="file docutils literal notranslate"><span class="pre">python3</span></code> binary.
<code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">altinstall</span></code> is therefore recommended instead of <code class="docutils literal notranslate"><span class="pre">make</span> <span class="pre">install</span></code>
since it only installs <code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em><span class="pre">/bin/python</span><em><span class="pre">version</span></em></code>.</p>
</div>
</section>
<section id="python-related-paths-and-files">
<h2><span class="section-number">2.3. </span>Python-related paths and files<a class="headerlink" href="#python-related-paths-and-files" title="Link to this heading"></a></h2>
<p>These are subject to difference depending on local installation conventions;
<a class="reference internal" href="configure.html#cmdoption-prefix"><code class="xref std std-option docutils literal notranslate"><span class="pre">prefix</span></code></a> and <a class="reference internal" href="configure.html#cmdoption-exec-prefix"><code class="xref std std-option docutils literal notranslate"><span class="pre">exec_prefix</span></code></a>
are installation-dependent and should be interpreted as for GNU software; they
may be the same.</p>
<p>For example, on most Linux systems, the default for both is <code class="file docutils literal notranslate"><span class="pre">/usr</span></code>.</p>
<table class="docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p>File/directory</p></th>
<th class="head"><p>Meaning</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em><span class="pre">/bin/python3</span></code></p></td>
<td><p>Recommended location of the interpreter.</p></td>
</tr>
<tr class="row-odd"><td><p><code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">version</span></em></code>,
<code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em><span class="pre">/lib/python</span><em><span class="pre">version</span></em></code></p></td>
<td><p>Recommended locations of the directories
containing the standard modules.</p></td>
</tr>
<tr class="row-even"><td><p><code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em><span class="pre">/include/python</span><em><span class="pre">version</span></em></code>,
<code class="file docutils literal notranslate"><em><span class="pre">exec_prefix</span></em><span class="pre">/include/python</span><em><span class="pre">version</span></em></code></p></td>
<td><p>Recommended locations of the directories
containing the include files needed for
developing Python extensions and
embedding the interpreter.</p></td>
</tr>
</tbody>
</table>
</section>
<section id="miscellaneous">
<h2><span class="section-number">2.4. </span>Miscellaneous<a class="headerlink" href="#miscellaneous" title="Link to this heading"></a></h2>
<p>To easily use Python scripts on Unix, you need to make them executable,
e.g. with</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>chmod<span class="w"> </span>+x<span class="w"> </span>script
</pre></div>
</div>
<p>and put an appropriate Shebang line at the top of the script. A good choice is
usually</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python3</span>
</pre></div>
</div>
<p>which searches for the Python interpreter in the whole <span class="target" id="index-0"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">PATH</span></code>. However,
some Unices may not have the <strong class="program">env</strong> command, so you may need to hardcode
<code class="docutils literal notranslate"><span class="pre">/usr/bin/python3</span></code> as the interpreter path.</p>
<p>To use shell commands in your Python scripts, look at the <a class="reference internal" href="../library/subprocess.html#module-subprocess" title="subprocess: Subprocess management."><code class="xref py py-mod docutils literal notranslate"><span class="pre">subprocess</span></code></a> module.</p>
</section>
<section id="custom-openssl">
<span id="unix-custom-openssl"></span><h2><span class="section-number">2.5. </span>Custom OpenSSL<a class="headerlink" href="#custom-openssl" title="Link to this heading"></a></h2>
<ol class="arabic">
<li><p>To use your vendors OpenSSL configuration and system trust store, locate
the directory with <code class="docutils literal notranslate"><span class="pre">openssl.cnf</span></code> file or symlink in <code class="docutils literal notranslate"><span class="pre">/etc</span></code>. On most
distribution the file is either in <code class="docutils literal notranslate"><span class="pre">/etc/ssl</span></code> or <code class="docutils literal notranslate"><span class="pre">/etc/pki/tls</span></code>. The
directory should also contain a <code class="docutils literal notranslate"><span class="pre">cert.pem</span></code> file and/or a <code class="docutils literal notranslate"><span class="pre">certs</span></code>
directory.</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>find<span class="w"> </span>/etc/<span class="w"> </span>-name<span class="w"> </span>openssl.cnf<span class="w"> </span>-printf<span class="w"> </span><span class="s2">&quot;%h\n&quot;</span>
<span class="go">/etc/ssl</span>
</pre></div>
</div>
</li>
<li><p>Download, build, and install OpenSSL. Make sure you use <code class="docutils literal notranslate"><span class="pre">install_sw</span></code> and
not <code class="docutils literal notranslate"><span class="pre">install</span></code>. The <code class="docutils literal notranslate"><span class="pre">install_sw</span></code> target does not override
<code class="docutils literal notranslate"><span class="pre">openssl.cnf</span></code>.</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>curl<span class="w"> </span>-O<span class="w"> </span>https://www.openssl.org/source/openssl-VERSION.tar.gz
<span class="gp">$ </span>tar<span class="w"> </span>xzf<span class="w"> </span>openssl-VERSION
<span class="gp">$ </span><span class="nb">pushd</span><span class="w"> </span>openssl-VERSION
<span class="gp">$ </span>./config<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--prefix<span class="o">=</span>/usr/local/custom-openssl<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--libdir<span class="o">=</span>lib<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--openssldir<span class="o">=</span>/etc/ssl
<span class="gp">$ </span>make<span class="w"> </span>-j1<span class="w"> </span>depend
<span class="gp">$ </span>make<span class="w"> </span>-j8
<span class="gp">$ </span>make<span class="w"> </span>install_sw
<span class="gp">$ </span><span class="nb">popd</span>
</pre></div>
</div>
</li>
<li><p>Build Python with custom OpenSSL
(see the configure <code class="docutils literal notranslate"><span class="pre">--with-openssl</span></code> and <code class="docutils literal notranslate"><span class="pre">--with-openssl-rpath</span></code> options)</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span><span class="nb">pushd</span><span class="w"> </span>python-3.x.x
<span class="gp">$ </span>./configure<span class="w"> </span>-C<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--with-openssl<span class="o">=</span>/usr/local/custom-openssl<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--with-openssl-rpath<span class="o">=</span>auto<span class="w"> </span><span class="se">\</span>
<span class="w"> </span>--prefix<span class="o">=</span>/usr/local/python-3.x.x
<span class="gp">$ </span>make<span class="w"> </span>-j8
<span class="gp">$ </span>make<span class="w"> </span>altinstall
</pre></div>
</div>
</li>
</ol>
<div class="admonition note">
<p class="admonition-title">Note</p>
<p>Patch releases of OpenSSL have a backwards compatible ABI. You dont need
to recompile Python to update OpenSSL. Its sufficient to replace the
custom OpenSSL installation with a newer version.</p>
</div>
</section>
</section>
<div class="clearer"></div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="Main">
<div class="sphinxsidebarwrapper">
<div>
<h3><a href="../contents.html">Table of Contents</a></h3>
<ul>
<li><a class="reference internal" href="#">2. Using Python on Unix platforms</a><ul>
<li><a class="reference internal" href="#getting-and-installing-the-latest-version-of-python">2.1. Getting and installing the latest version of Python</a><ul>
<li><a class="reference internal" href="#on-linux">2.1.1. On Linux</a><ul>
<li><a class="reference internal" href="#installing-idle">2.1.1.1. Installing IDLE</a></li>
</ul>
</li>
<li><a class="reference internal" href="#on-freebsd-and-openbsd">2.1.2. On FreeBSD and OpenBSD</a></li>
</ul>
</li>
<li><a class="reference internal" href="#building-python">2.2. Building Python</a></li>
<li><a class="reference internal" href="#python-related-paths-and-files">2.3. Python-related paths and files</a></li>
<li><a class="reference internal" href="#miscellaneous">2.4. Miscellaneous</a></li>
<li><a class="reference internal" href="#custom-openssl">2.5. Custom OpenSSL</a></li>
</ul>
</li>
</ul>
</div>
<div>
<h4>Previous topic</h4>
<p class="topless"><a href="cmdline.html"
title="previous chapter"><span class="section-number">1. </span>Command line and environment</a></p>
</div>
<div>
<h4>Next topic</h4>
<p class="topless"><a href="configure.html"
title="next chapter"><span class="section-number">3. </span>Configure Python</a></p>
</div>
<div role="note" aria-label="source link">
<h3>This Page</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">Report a Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/main/Doc/using/unix.rst"
rel="nofollow">Show Source
</a>
</li>
</ul>
</div>
</div>
<div id="sidebarbutton" title="Collapse sidebar">
<span>«</span>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="Related">
<h3>Navigation</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="General Index"
>index</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python Module Index"
>modules</a> |</li>
<li class="right" >
<a href="configure.html" title="3. Configure Python"
>next</a> |</li>
<li class="right" >
<a href="cmdline.html" title="1. Command line and environment"
>previous</a> |</li>
<li><img src="../_static/py.svg" alt="Python logo" style="vertical-align: middle; margin-top: -1px"/></li>
<li><a href="https://www.python.org/">Python</a> &#187;</li>
<li class="switchers">
<div class="language_switcher_placeholder"></div>
<div class="version_switcher_placeholder"></div>
</li>
<li>
</li>
<li id="cpython-language-and-version">
<a href="../index.html">3.13.3 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >Python Setup and Usage</a> &#187;</li>
<li class="nav-item nav-item-this"><a href=""><span class="section-number">2. </span>Using Python on Unix platforms</a></li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="Quick search" aria-label="Quick search" type="search" name="q" id="search-box" />
<input type="submit" value="Go" />
</form>
</div>
|
</li>
<li class="right">
<label class="theme-selector-label">
Theme
<select class="theme-selector" oninput="activateTheme(this.value)">
<option value="auto" selected>Auto</option>
<option value="light">Light</option>
<option value="dark">Dark</option>
</select>
</label> |</li>
</ul>
</div>
<div class="footer">
&copy;
<a href="../copyright.html">
Copyright
</a>
2001-2025, Python Software Foundation.
<br />
This page is licensed under the Python Software Foundation License Version 2.
<br />
Examples, recipes, and other code in the documentation are additionally licensed under the Zero Clause BSD License.
<br />
See <a href="/license.html">History and License</a> for more information.<br />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
Last updated on Apr 08, 2025 (14:33 UTC).
<a href="/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff