增加python文档

This commit is contained in:
2025-03-09 17:10:56 +08:00
parent 7153217140
commit 723430cade
1039 changed files with 699509 additions and 0 deletions

View File

@@ -0,0 +1,225 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>&lt;no title&gt; &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/_setuptools_disclaimer.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/_setuptools_disclaimer.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/_setuptools_disclaimer.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档只有在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之前,才会单独保留。</p>
</div>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/_setuptools_disclaimer.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,639 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>5. 创建构建分发版 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="6. Distutils 示例" href="examples.html" />
<link rel="prev" title="4. 创建源代码分发包" href="sourcedist.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/builtdist.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">5. 创建构建分发版</a><ul>
<li><a class="reference internal" href="#creating-rpm-packages">5.1. 创建RPM软件包</a></li>
<li><a class="reference internal" href="#creating-windows-installers">5.2. Creating Windows Installers</a></li>
<li><a class="reference internal" href="#cross-compiling-on-windows">5.3. 在 Windows 上的交叉编译</a><ul>
<li><a class="reference internal" href="#the-postinstallation-script">5.3.1. 安装后脚本</a></li>
</ul>
</li>
<li><a class="reference internal" href="#vista-user-access-control-uac">5.4. Vista User Access Control (UAC)</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="sourcedist.html"
title="上一章"><span class="section-number">4. </span>创建源代码分发包</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="examples.html"
title="下一章"><span class="section-number">6. </span>Distutils 示例</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/builtdist.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/builtdist.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="examples.html" title="6. Distutils 示例"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="sourcedist.html" title="4. 创建源代码分发包"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="creating-built-distributions">
<span id="built-dist"></span><h1><span class="section-number">5. </span>创建构建分发版<a class="headerlink" href="#creating-built-distributions" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档是历史遗留文档,在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之后,将不再单独作为正式文档保留。</p>
</div>
<p>“构建分发版”即你通常所认为的“二进制包”或“安装程序”(取决于你的技术背景)。 但它并不一定是二进制的,因为它可能只包含 Python 源代码和/或字节码;并且我们也不将其称为包,因为这个词在 Python 中已经被使用。 (而“安装程序”是主流桌面系统领域的一个专有术语。)</p>
<p>分发版可以让你的模块分发安装器尽可能地方便易用:对于基于 RPM 的 Linux 系统的用户,它将为二进制 RPM对于 Windows 的用户,它将为可执行文件安装器;对于基于 Debian 的 Linux 用户,它将为 Debian 安装包;诸如此类。 显然,没有人能为世界上所有的系统平台都构建分发版,因此 Distutils 被设计用来让模块开发者能够专注于他们的专长 --- 编写代码并创建源代码分发版 --- 而让另一群作为中介的 <em>打包者</em> 负责在尽可能多的受支持系统平台上将源代码分发版转换为构建分发版。</p>
<p>当然,模块开发者可以是自己模块的打包者;或者打包者也可以是住在别处的“某一位”能够接触到原始开发者接触不到的特定系统平台的志愿者;或者还可以是一个定期抓取新的源代码分发版并在尽可能多的受支持系统平台上将其转换为构建分发版的软件。 无论他们属于哪一种,打包者都会使用设置脚本和 <strong class="command">bdist</strong> 命令族来生成构建分发版。</p>
<p>作为一个简单示例,如果我在 Distutils 源代码树中运行以下命令:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist</span>
</pre></div>
</div>
<p>则 Distutils 将构建我的模块分发版(在此情况下即 Distutils 本身),执行“模拟”安装(同样是在 <code class="file docutils literal notranslate"><span class="pre">build</span></code> 目录中),并为我的系统平台创建默认类型的构建分发版。 构建分发版的默认格式在 Unix 上是一个“非自动” tar 文件,而在 Windows 上则是一个简单的可执行文件安装器。 (此 tar 文件被称为“非自动”是因为它必须在指定的位置上解包方可使用。)</p>
<p>这样,上述命令在 Unix 系统上将会创建 <code class="file docutils literal notranslate"><span class="pre">Distutils-1.0.</span><em><span class="pre">plat</span></em><span class="pre">.tar.gz</span></code>;在正确的位置上解包这个 tar 文件将会装好 Distutils就像是你下载了源代码分发版并运行 <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></code> 一样。 (这个“正确的位置”可能是文件系统根目录或 Python 的 <code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em></code> 目录,具体取决于提供给 <strong class="command">bdist_dumb</strong> 命令的选项;在默认情况下是相对于 <code class="file docutils literal notranslate"><em><span class="pre">prefix</span></em></code> 创建非自动颁发版。)</p>
<p>显然,对于纯粹的 Python 分发版来说,这并不比运行 <code class="docutils literal notranslate"><span class="pre">python</span> <span class="pre">setup.py</span> <span class="pre">install</span></code> 更简单 --- 但是对于包括需要被编译的扩展的非纯粹的分发版来说,就可能是有人能使用你的扩展而有人不能使用的差别。 而创建“自动”构建分发版,例如 RPM 包或 Windows 的可执行文件安装器,对于用户来说就会更加方便,即使你的分发版不包括任何扩展。</p>
<p><strong class="command">bdist</strong> 命令有一个 <code class="xref std std-option docutils literal notranslate"><span class="pre">--formats</span></code> 选项,与 <strong class="command">sdist</strong> 命令类似,你可以用该选项来选择要生成的构建分发版类型:例如,:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist</span> <span class="o">--</span><span class="nb">format</span><span class="o">=</span><span class="nb">zip</span>
</pre></div>
</div>
<p>当在 Unix 系统上运行时,会再次创建 <code class="file docutils literal notranslate"><span class="pre">Distutils-1.0.</span><em><span class="pre">plat</span></em><span class="pre">.zip</span></code>,这个归档文件将从根目录被解包以安装 Distutils。</p>
<p>构建分发版的可用格式有:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 25%" />
<col style="width: 58%" />
<col style="width: 17%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>格式</p></th>
<th class="head"><p>描述</p></th>
<th class="head"><p>备注</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">gztar</span></code></p></td>
<td><p>gzipped tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.gz</span></code>)</p></td>
<td><p>(1)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">bztar</span></code></p></td>
<td><p>bzipped tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.bz2</span></code>)</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">xztar</span></code></p></td>
<td><p>xzipped tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.xz</span></code>)</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">ztar</span></code></p></td>
<td><p>带压缩的 tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.Z</span></code>)</p></td>
<td><p>(3)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">tar</span></code></p></td>
<td><p>tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar</span></code>)</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">zip</span></code></p></td>
<td><p>zip 文件 (<code class="file docutils literal notranslate"><span class="pre">.zip</span></code>)</p></td>
<td><p>(2),(4)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">rpm</span></code></p></td>
<td><p>RPM</p></td>
<td><p>(5)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">pkgtool</span></code></p></td>
<td><p>Solaris <strong class="program">pkgtool</strong></p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">sdux</span></code></p></td>
<td><p>HP-UX <strong class="program">swinstall</strong></p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">wininst</span></code></p></td>
<td><p>Windows的自解压ZIP文件</p></td>
<td><p>(4)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">msi</span></code></p></td>
<td><p>Microsoft安装程序。</p></td>
<td></td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版更改: </span>添加了对 <code class="docutils literal notranslate"><span class="pre">xztar</span></code> 格式的支持</p>
</div>
<p>注释:</p>
<ol class="arabic simple">
<li><p>默认 Unix</p></li>
<li><p>默认Windows</p></li>
<li><p>需要外部 <strong class="program">compress</strong> 工具。</p></li>
<li><p>需要有外部 <strong class="program">zip</strong> 工具或 <a class="reference internal" href="../library/zipfile.html#module-zipfile" title="zipfile: Read and write ZIP-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipfile</span></code></a> 模块(自 Python 1.6 起是标准 Python 库的一部分)</p></li>
<li><p>需要有外部 <strong class="program">rpm</strong> 工具,版本号为 3.0.4 或以上(可使用 <code class="docutils literal notranslate"><span class="pre">rpm</span> <span class="pre">--version</span></code> 查看你所使用的版本)</p></li>
</ol>
<p>你不必附带 <code class="xref std std-option docutils literal notranslate"><span class="pre">--formats</span></code> 来使用 <strong class="command">bdist</strong> 命令;你还可以使用直接实现了你想要的特定格式的命令。 某些这样的 <strong class="command">bdist</strong> &quot;子命令&quot; 实际上会生成几种相似的格式;例如,<strong class="command">bdist_dumb</strong> 命令将生成所有 &quot;非自动&quot; 归档格式 (<code class="docutils literal notranslate"><span class="pre">tar</span></code>, <code class="docutils literal notranslate"><span class="pre">gztar</span></code>, <code class="docutils literal notranslate"><span class="pre">bztar</span></code>, <code class="docutils literal notranslate"><span class="pre">xztar</span></code>, <code class="docutils literal notranslate"><span class="pre">ztar</span></code><code class="docutils literal notranslate"><span class="pre">zip</span></code>),而 <strong class="command">bdist_rpm</strong> 将同时生成二进制和源代码 RPM。 <strong class="command">bdist</strong> 子命令以及每个子命令所生成的格式如下:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 41%" />
<col style="width: 59%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>命令</p></th>
<th class="head"><p>格式</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><strong class="command">bdist_dumb</strong></p></td>
<td><p>tar, gztar, bztar, xztar, ztar, zip</p></td>
</tr>
<tr class="row-odd"><td><p><strong class="command">bdist_rpm</strong></p></td>
<td><p>rpm, srpm</p></td>
</tr>
<tr class="row-even"><td><p><strong class="command">bdist_wininst</strong></p></td>
<td><p>wininst</p></td>
</tr>
<tr class="row-odd"><td><p><strong class="command">bdist_msi</strong></p></td>
<td><p>msi</p></td>
</tr>
</tbody>
</table>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>从Python 3.8开始不推荐使用 bdist_wininst</p>
</div>
<p>以下小节提供了每个 <strong class="command">bdist_*</strong> 命令的详情。</p>
<section id="creating-rpm-packages">
<span id="creating-rpms"></span><h2><span class="section-number">5.1. </span>创建RPM软件包<a class="headerlink" href="#creating-rpm-packages" title="永久链接至标题"></a></h2>
<p>RPM 格式被许多流行的 Linux 发行版所使用,包括 Red Hat, SuSE 和 Mandrake。 如果其中(或任何其他基于 RPM 的 Linux 发行版)的某一个是你的常用环境,那么为相同发行版的其他用户创建 RPM 包是很容易的。 根据你的模块分发版的复杂度以及 Linux 发行版之间的差异性,你还可能创建适用于多个基于 RPM 的发行版的 RPM 包。</p>
<p>为你的模块分发版创建 RPM 的通常方式是运行 <strong class="command">bdist_rpm</strong> 命令:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist_rpm</span>
</pre></div>
</div>
<p>或者 <strong class="command">bdist</strong> 命令附带 <code class="xref std std-option docutils literal notranslate"><span class="pre">--format</span></code> 选项:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist</span> <span class="o">--</span><span class="n">formats</span><span class="o">=</span><span class="n">rpm</span>
</pre></div>
</div>
<p>前者允许你指定 RPM 专属的选项;后者允许你方便地一次性指定多种格式。 如果这两样你全都要,你可以显式地指定多个 <strong class="command">bdist_*</strong> 命令及其选项:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist_rpm</span> <span class="o">--</span><span class="n">packager</span><span class="o">=</span><span class="s2">&quot;John Doe &lt;jdoe@example.org&gt;&quot;</span> \
<span class="n">bdist_wininst</span> <span class="o">--</span><span class="n">target</span><span class="o">-</span><span class="n">version</span><span class="o">=</span><span class="s2">&quot;2.0&quot;</span>
</pre></div>
</div>
<p>创建 RPM 包的操作是由 <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件驱动的,就像 Distutils 的使用是由 setup 脚本驱动的一样。 为了让你更方便,<strong class="command">bdist_rpm</strong> 命令通常会根据你在 setup 脚本、命令行和任意 Distutils 配置文件中提供的信息创建一个 <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件。 <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件中的各种选项和小节从 setup 脚本中派生的情况如下:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 48%" />
<col style="width: 52%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>RPM <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件配置或选项</p></th>
<th class="head"><p>Distutils安装脚本选项</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>名称</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">name</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>摘要(在序言中)</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">description</span></code></p></td>
</tr>
<tr class="row-even"><td><p>版本</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">version</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>供应商</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">author</span></code><code class="docutils literal notranslate"><span class="pre">author_email</span></code>, 或 --- &amp; <code class="docutils literal notranslate"><span class="pre">maintainer</span></code><code class="docutils literal notranslate"><span class="pre">maintainer_email</span></code></p></td>
</tr>
<tr class="row-even"><td><p>版权所有</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">license</span></code></p></td>
</tr>
<tr class="row-odd"><td><p>Url</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">url</span></code></p></td>
</tr>
<tr class="row-even"><td><p>%d描述部分</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">long_description</span></code></p></td>
</tr>
</tbody>
</table>
<p>此外,在 <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件中还有许多选项在 setup 脚本中没有对应的选项。 这些选项大多是通过传给 <strong class="command">bdist_rpm</strong> 命令的选项来处理的,如下所示:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 36%" />
<col style="width: 34%" />
<col style="width: 29%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>RPM <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件配置或选项</p></th>
<th class="head"><p><strong class="command">bdist_rpm</strong> 选项</p></th>
<th class="head"><p>默认值</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>发布版本</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">release</span></code></p></td>
<td><p>&quot;1&quot;</p></td>
</tr>
<tr class="row-odd"><td><p>组织</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">group</span></code></p></td>
<td><p>&quot;Development/Libraries&quot;</p></td>
</tr>
<tr class="row-even"><td><p>供应商</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">vendor</span></code></p></td>
<td><p>(同上)</p></td>
</tr>
<tr class="row-odd"><td><p>打包</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">packager</span></code></p></td>
<td><p>(none)</p></td>
</tr>
<tr class="row-even"><td><p>提供</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">provides</span></code></p></td>
<td><p>(none)</p></td>
</tr>
<tr class="row-odd"><td><p>需求</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">requires</span></code></p></td>
<td><p>(none)</p></td>
</tr>
<tr class="row-even"><td><p>冲突</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">conflicts</span></code></p></td>
<td><p>(none)</p></td>
</tr>
<tr class="row-odd"><td><p>淘汰</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">obsoletes</span></code></p></td>
<td><p>(none)</p></td>
</tr>
<tr class="row-even"><td><p>Distribution</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">distribution_name</span></code></p></td>
<td><p>(none)</p></td>
</tr>
<tr class="row-odd"><td><p>构建要求</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">build_requires</span></code></p></td>
<td><p>(none)</p></td>
</tr>
<tr class="row-even"><td><p>Icon</p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">icon</span></code></p></td>
<td><p>(none)</p></td>
</tr>
</tbody>
</table>
<p>显然,即使是在命令行中提供少量的此类选项也是很繁琐易出错的,因此通常最好是将它们放在 setup 配置文件 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> 中,参见 <a class="reference internal" href="configfile.html#setup-config"><span class="std std-ref">编写设置脚本的配置文件</span></a> 一节。 如果你要分发或打包许多 Python 模块分发版,你可能会需要将适用于所有这些分发版的选项放在你私人的 Distutils 配置文件中 (<code class="file docutils literal notranslate"><span class="pre">~/.pydistutils.cfg</span></code>)。 如果你想要临时禁用此文件,你可以将 <code class="xref std std-option docutils literal notranslate"><span class="pre">--no-user-cfg</span></code> 选项传给 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code></p>
<p>构建一个二进制 RPM 包有三个步骤,它们全都是由 Distutils 自动处理的:</p>
<ol class="arabic simple">
<li><p>创建一个 <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件,该文件对包进行了描述(类似于 Distutils setup 脚本;实际上 setup 脚本中的许多信息都会出现在 <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件中)</p></li>
<li><p>创建源 RPM</p></li>
<li><p>创建“二进制”RPM其中可能包含二进制代码也可能不包含具体取决于你的模块分发版是否包含 Python 扩展)</p></li>
</ol>
<p>通常RPM 会将后两个步骤捆绑在一起;当你使用 Distutils 时,三个步骤通常都会捆绑在一起。</p>
<p>如果你愿意,你也可以将这三个步骤分开。 你可以使用 <code class="xref std std-option docutils literal notranslate"><span class="pre">--spec-only</span></code> 选项来让 <strong class="command">bdist_rpm</strong> 只创建 <code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件并退出;在这种情况下,<code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件将被写到“分发目录” --- 通常为 <code class="file docutils literal notranslate"><span class="pre">dist/</span></code>,但可通过 <code class="xref std std-option docutils literal notranslate"><span class="pre">--dist-dir</span></code> 选项来自定义。 (通常,<code class="file docutils literal notranslate"><span class="pre">.spec</span></code> 文件会位于“构建树”的深处,在 <strong class="command">bdist_rpm</strong> 所创建的一个临时目录中。)</p>
</section>
<section id="creating-windows-installers">
<span id="creating-wininst"></span><h2><span class="section-number">5.2. </span>Creating Windows Installers<a class="headerlink" href="#creating-windows-installers" title="永久链接至标题"></a></h2>
<div class="admonition warning">
<p class="admonition-title">警告</p>
<p>从Python 3.8开始不推荐使用 bdist_wininst</p>
</div>
<p>Executable installers are the natural format for binary distributions on
Windows. They display a nice graphical user interface, display some information
about the module distribution to be installed taken from the metadata in the
setup script, let the user select a few options, and start or cancel the
installation.</p>
<p>Since the metadata is taken from the setup script, creating Windows installers
is usually as easy as running:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist_wininst</span>
</pre></div>
</div>
<p>or the <strong class="command">bdist</strong> command with the <code class="xref std std-option docutils literal notranslate"><span class="pre">--formats</span></code> option:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist</span> <span class="o">--</span><span class="n">formats</span><span class="o">=</span><span class="n">wininst</span>
</pre></div>
</div>
<p>If you have a pure module distribution (only containing pure Python modules and
packages), the resulting installer will be version independent and have a name
like <code class="file docutils literal notranslate"><span class="pre">foo-1.0.win32.exe</span></code>. Note that creating <code class="docutils literal notranslate"><span class="pre">wininst</span></code> binary
distributions in only supported on Windows systems.</p>
<p>If you have a non-pure distribution, the extensions can only be created on a
Windows platform, and will be Python version dependent. The installer filename
will reflect this and now has the form <code class="file docutils literal notranslate"><span class="pre">foo-1.0.win32-py2.0.exe</span></code>. You
have to create a separate installer for every Python version you want to
support.</p>
<p>The installer will try to compile pure modules into <a class="reference internal" href="../glossary.html#term-bytecode"><span class="xref std std-term">bytecode</span></a> after installation
on the target system in normal and optimizing mode. If you don't want this to
happen for some reason, you can run the <strong class="command">bdist_wininst</strong> command with
the <code class="xref std std-option docutils literal notranslate"><span class="pre">--no-target-compile</span></code> and/or the <code class="xref std std-option docutils literal notranslate"><span class="pre">--no-target-optimize</span></code>
option.</p>
<p>By default the installer will display the cool &quot;Python Powered&quot; logo when it is
run, but you can also supply your own 152x261 bitmap which must be a Windows
<code class="file docutils literal notranslate"><span class="pre">.bmp</span></code> file with the <code class="xref std std-option docutils literal notranslate"><span class="pre">--bitmap</span></code> option.</p>
<p>The installer will also display a large title on the desktop background window
when it is run, which is constructed from the name of your distribution and the
version number. This can be changed to another text by using the
<code class="xref std std-option docutils literal notranslate"><span class="pre">--title</span></code> option.</p>
<p>The installer file will be written to the &quot;distribution directory&quot; --- normally
<code class="file docutils literal notranslate"><span class="pre">dist/</span></code>, but customizable with the <code class="xref std std-option docutils literal notranslate"><span class="pre">--dist-dir</span></code> option.</p>
</section>
<section id="cross-compiling-on-windows">
<span id="cross-compile-windows"></span><h2><span class="section-number">5.3. </span>在 Windows 上的交叉编译<a class="headerlink" href="#cross-compiling-on-windows" title="永久链接至标题"></a></h2>
<p>从 Python 2.6 开始distutils 能够在不同 Windows 平台之间执行交叉编译。 实际上,这意味着只要安装了正确的工具,你可以使用 32 位版 Windows 来创建 64 位的扩展或是反向操作。</p>
<p>要针对替代平台进行编译,请为构建命令指定 <code class="xref std std-option docutils literal notranslate"><span class="pre">--plat-name</span></code> 选项。 目前的有效值为 'win32' 和d 'win-amd64'。 例如,在 32 位版 Windows 上,你可以执行:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">build</span> <span class="o">--</span><span class="n">plat</span><span class="o">-</span><span class="n">name</span><span class="o">=</span><span class="n">win</span><span class="o">-</span><span class="n">amd64</span>
</pre></div>
</div>
<p>to build a 64bit version of your extension. The Windows Installers also
support this option, so the command:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">build</span> <span class="o">--</span><span class="n">plat</span><span class="o">-</span><span class="n">name</span><span class="o">=</span><span class="n">win</span><span class="o">-</span><span class="n">amd64</span> <span class="n">bdist_wininst</span>
</pre></div>
</div>
<p>将在你的 32 位版 Windows 上创建一个 64 位版的安装程序可执行文件。</p>
<p>要进行交叉编译,你必须下载 Python 源代码并针对你的目标平台交叉编译 Python 本身 —— 使用 Python 的二进制安装版是无法做到的(因为其中不包括针对其他平台的 .lib 等文件。) 实际上,这意味着 32 位操作系统的用户将需要使用 Visual Studio 2008 来打开 Python 源代码目录树下的 <code class="file docutils literal notranslate"><span class="pre">PCbuild/PCbuild.sln</span></code> 解决方案并构建 'pythoncore' 项目的 &quot;x64&quot; 配置之后才能进行扩展的交叉编译。</p>
<p>请注意在默认情况下Visual Studio 2008 并不会安装 64 位编译器或工具。 你可能需要重新执行 Visual Studio 安装过程并选择这些工具(使用控制面板 -&gt; [添加/移除] 程序是检查或修改你的现有安装的一个便捷方式。)</p>
<section id="the-postinstallation-script">
<span id="postinstallation-script"></span><h3><span class="section-number">5.3.1. </span>安装后脚本<a class="headerlink" href="#the-postinstallation-script" title="永久链接至标题"></a></h3>
<p>从 Python 2.3 开始,可以通过 <code class="xref std std-option docutils literal notranslate"><span class="pre">--install-script</span></code> 选项指定一个安装后脚本。 必须要指定脚本的主文件名,并且该脚本文件名还必须在传给 setup 函数的参数中列出。</p>
<p>在安装时当所有文件拷贝完毕后该脚本将会在目标系统上运行,并将 <code class="docutils literal notranslate"><span class="pre">argv[1]</span></code> 设为 <code class="xref std std-option docutils literal notranslate"><span class="pre">-install</span></code>,而在卸载时当文件被移除前会再次运行并将 <code class="docutils literal notranslate"><span class="pre">argv[1]</span></code> 设为 <code class="xref std std-option docutils literal notranslate"><span class="pre">-remove</span></code></p>
<p>安装脚本嵌入在 Windows 安装程序中运行,每个输出 (<code class="docutils literal notranslate"><span class="pre">sys.stdout</span></code>, <code class="docutils literal notranslate"><span class="pre">sys.stderr</span></code>) 都会被重定向到一个缓冲区并将在脚本完成后显示到 GUI 中。</p>
<p>一些在此上下文中特别有用的功能在安装脚本中作为附加内置函数被提供。</p>
<dl class="function">
<dt id="directory_created">
<code class="sig-name descname">directory_created</code><span class="sig-paren">(</span><em class="sig-param">path</em><span class="sig-paren">)</span><a class="headerlink" href="#directory_created" title="永久链接至目标"></a></dt>
<dt id="file_created">
<code class="sig-name descname">file_created</code><span class="sig-paren">(</span><em class="sig-param">path</em><span class="sig-paren">)</span><a class="headerlink" href="#file_created" title="永久链接至目标"></a></dt>
<dd><p>这些函数应当在安装时的安装后脚本创建某个目录或文件时被调用。 它会将 <em>path</em> 注册到卸载程序,这样当分发版被卸载时它将被移除。 安全起见,目录只有在为空时才会被移除。</p>
</dd></dl>
<dl class="function">
<dt id="get_special_folder_path">
<code class="sig-name descname">get_special_folder_path</code><span class="sig-paren">(</span><em class="sig-param">csidl_string</em><span class="sig-paren">)</span><a class="headerlink" href="#get_special_folder_path" title="永久链接至目标"></a></dt>
<dd><p>此函数可被用来获取 Windows 中的特殊文件夹位置如 Start Menu 或 Desktop。 它将返回相应文件夹的完整路径。 <em>csidl_string</em> 必须为下列字符串之一:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="s2">&quot;CSIDL_APPDATA&quot;</span>
<span class="s2">&quot;CSIDL_COMMON_STARTMENU&quot;</span>
<span class="s2">&quot;CSIDL_STARTMENU&quot;</span>
<span class="s2">&quot;CSIDL_COMMON_DESKTOPDIRECTORY&quot;</span>
<span class="s2">&quot;CSIDL_DESKTOPDIRECTORY&quot;</span>
<span class="s2">&quot;CSIDL_COMMON_STARTUP&quot;</span>
<span class="s2">&quot;CSIDL_STARTUP&quot;</span>
<span class="s2">&quot;CSIDL_COMMON_PROGRAMS&quot;</span>
<span class="s2">&quot;CSIDL_PROGRAMS&quot;</span>
<span class="s2">&quot;CSIDL_FONTS&quot;</span>
</pre></div>
</div>
<p>如果文件夹不能被检索到,会触发 <a class="reference internal" href="../library/exceptions.html#OSError" title="OSError"><code class="xref py py-exc docutils literal notranslate"><span class="pre">OSError</span></code></a></p>
<p>有哪些可用的文件夹取决于的 Windows 的具体版本,并可能受特定配置的影响。 更多细节请参考 Microsoft 有关 <code class="xref c c-func docutils literal notranslate"><span class="pre">SHGetSpecialFolderPath()</span></code> 函数的文档。</p>
</dd></dl>
<dl class="function">
<dt id="create_shortcut">
<code class="sig-name descname">create_shortcut</code><span class="sig-paren">(</span><em class="sig-param">target</em>, <em class="sig-param">description</em>, <em class="sig-param">filename</em><span class="optional">[</span>, <em class="sig-param">arguments</em><span class="optional">[</span>, <em class="sig-param">workdir</em><span class="optional">[</span>, <em class="sig-param">iconpath</em><span class="optional">[</span>, <em class="sig-param">iconindex</em><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="optional">]</span><span class="sig-paren">)</span><a class="headerlink" href="#create_shortcut" title="永久链接至目标"></a></dt>
<dd><p>此函数会创建一个快捷方式。 <em>target</em> 是此快捷方式要启动的程序的路径。 <em>description</em> 是快捷方式的描述文本。 <em>filename</em> 是用户将看到的快捷方式的标题。 <em>arguments</em> 指定命令行参数,如果有的话。 <em>workdir</em> 是程序的工作目录。 <em>iconpath</em> 是包含快捷方式的图标的文件,而 <em>iconindex</em><em>iconpath</em> 文件中图标的索引号。 同样地,更多细节请参考 Microsoft 有关 <code class="xref py py-class docutils literal notranslate"><span class="pre">IShellLink</span></code> 接口的文档。</p>
</dd></dl>
</section>
</section>
<section id="vista-user-access-control-uac">
<h2><span class="section-number">5.4. </span>Vista User Access Control (UAC)<a class="headerlink" href="#vista-user-access-control-uac" title="永久链接至标题"></a></h2>
<p>Starting with Python 2.6, bdist_wininst supports a <code class="xref std std-option docutils literal notranslate"><span class="pre">--user-access-control</span></code>
option. The default is 'none' (meaning no UAC handling is done), and other
valid values are 'auto' (meaning prompt for UAC elevation if Python was
installed for all users) and 'force' (meaning always prompt for elevation).</p>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>从Python 3.8开始不推荐使用 bdist_wininst</p>
</div>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">5. 创建构建分发版</a><ul>
<li><a class="reference internal" href="#creating-rpm-packages">5.1. 创建RPM软件包</a></li>
<li><a class="reference internal" href="#creating-windows-installers">5.2. Creating Windows Installers</a></li>
<li><a class="reference internal" href="#cross-compiling-on-windows">5.3. 在 Windows 上的交叉编译</a><ul>
<li><a class="reference internal" href="#the-postinstallation-script">5.3.1. 安装后脚本</a></li>
</ul>
</li>
<li><a class="reference internal" href="#vista-user-access-control-uac">5.4. Vista User Access Control (UAC)</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="sourcedist.html"
title="上一章"><span class="section-number">4. </span>创建源代码分发包</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="examples.html"
title="下一章"><span class="section-number">6. </span>Distutils 示例</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/builtdist.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="examples.html" title="6. Distutils 示例"
>下一页</a> |</li>
<li class="right" >
<a href="sourcedist.html" title="4. 创建源代码分发包"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,338 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>8. 命令参考 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="9. API参考引用" href="apiref.html" />
<link rel="prev" title="7. 扩展 Distutils" href="extending.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/commandref.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">8. 命令参考</a><ul>
<li><a class="reference internal" href="#installing-modules-the-install-command-family">8.1. 安装模块: <strong class="command">install</strong> 命令族</a><ul>
<li><a class="reference internal" href="#install-data">8.1.1. <strong class="command">install_data</strong></a></li>
<li><a class="reference internal" href="#install-scripts">8.1.2. <strong class="command">install_scripts</strong></a></li>
</ul>
</li>
<li><a class="reference internal" href="#creating-a-source-distribution-the-sdist-command">8.2. 创建源码发行包: <strong class="command">sdist</strong> 命令</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="extending.html"
title="上一章"><span class="section-number">7. </span>扩展 Distutils</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="apiref.html"
title="下一章"><span class="section-number">9. </span>API参考引用</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/commandref.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/commandref.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="apiref.html" title="9. API参考引用"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="extending.html" title="7. 扩展 Distutils"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="command-reference">
<span id="reference"></span><h1><span class="section-number">8. </span>命令参考<a class="headerlink" href="#command-reference" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档是历史遗留文档,在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之后,将不再单独作为正式文档保留。</p>
</div>
<section id="installing-modules-the-install-command-family">
<span id="install-cmd"></span><h2><span class="section-number">8.1. </span>安装模块: <strong class="command">install</strong> 命令族<a class="headerlink" href="#installing-modules-the-install-command-family" title="永久链接至标题"></a></h2>
<p>install 命令会确保 build 命令已经运行,然后运行子命令 <strong class="command">install_lib</strong>, <strong class="command">install_data</strong><strong class="command">install_scripts</strong></p>
<section id="install-data">
<span id="install-data-cmd"></span><h3><span class="section-number">8.1.1. </span><strong class="command">install_data</strong><a class="headerlink" href="#install-data" title="永久链接至标题"></a></h3>
<p>此命令会安装随发行包一同提供的所有数据文件。</p>
</section>
<section id="install-scripts">
<span id="install-scripts-cmd"></span><h3><span class="section-number">8.1.2. </span><strong class="command">install_scripts</strong><a class="headerlink" href="#install-scripts" title="永久链接至标题"></a></h3>
<p>此命令会安装发行包中的所有Python脚本。</p>
</section>
</section>
<section id="creating-a-source-distribution-the-sdist-command">
<span id="sdist-cmd"></span><h2><span class="section-number">8.2. </span>创建源码发行包: <strong class="command">sdist</strong> 命令<a class="headerlink" href="#creating-a-source-distribution-the-sdist-command" title="永久链接至标题"></a></h2>
<p>列出的模板命令有:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 48%" />
<col style="width: 52%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>命令</p></th>
<th class="head"><p>描述</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><strong class="command">include pat1 pat2 ...</strong></p></td>
<td><p>包括与列出的模式匹配的所有文件</p></td>
</tr>
<tr class="row-odd"><td><p><strong class="command">exclude pat1 pat2 ...</strong></p></td>
<td><p>排除与列出的模式匹配的所有文件</p></td>
</tr>
<tr class="row-even"><td><p><strong class="command">recursive-include dir pat1 pat2
...</strong></p></td>
<td><p>包括 <em>dir</em> 下与列出的模式匹配的所有文件</p></td>
</tr>
<tr class="row-odd"><td><p><strong class="command">recursive-exclude dir pat1 pat2
...</strong></p></td>
<td><p>排除 <em>dir</em> 下与列出的模式匹配的所有文件</p></td>
</tr>
<tr class="row-even"><td><p><strong class="command">global-include pat1 pat2 ...</strong></p></td>
<td><p>包括与源树匹配的所有文件---和任何列出的模式</p></td>
</tr>
<tr class="row-odd"><td><p><strong class="command">global-exclude pat1 pat2 ...</strong></p></td>
<td><p>排除与源树匹配的所有文件---和任何列出的模式</p></td>
</tr>
<tr class="row-even"><td><p><strong class="command">prune dir</strong></p></td>
<td><p>排除 <em>dir</em> 下的所有文件</p></td>
</tr>
<tr class="row-odd"><td><p><strong class="command">graft dir</strong></p></td>
<td><p>包括 <em>dir</em> 下的所有文件</p></td>
</tr>
</tbody>
</table>
<p>此处的模式是 Unix 风格的 &quot;glob&quot; 模式: <code class="docutils literal notranslate"><span class="pre">*</span></code> 匹配任意的常规文件名字符序列,<code class="docutils literal notranslate"><span class="pre">?</span></code> 匹配任意单个常规文件名字符,而 <code class="docutils literal notranslate"><span class="pre">[range]</span></code> 匹配 <em>range</em> 范围内的任意字符 (例如 <code class="docutils literal notranslate"><span class="pre">a-z</span></code>, <code class="docutils literal notranslate"><span class="pre">a-zA-Z</span></code>, <code class="docutils literal notranslate"><span class="pre">a-f0-9_.</span></code>)。 “常规文件名字符”的定义取决于具体平台:在 Unix 上是指正斜杠以外的任何字符;在 Windows 则是指反斜杠或冒号以外的任何字符。</p>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">8. 命令参考</a><ul>
<li><a class="reference internal" href="#installing-modules-the-install-command-family">8.1. 安装模块: <strong class="command">install</strong> 命令族</a><ul>
<li><a class="reference internal" href="#install-data">8.1.1. <strong class="command">install_data</strong></a></li>
<li><a class="reference internal" href="#install-scripts">8.1.2. <strong class="command">install_scripts</strong></a></li>
</ul>
</li>
<li><a class="reference internal" href="#creating-a-source-distribution-the-sdist-command">8.2. 创建源码发行包: <strong class="command">sdist</strong> 命令</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="extending.html"
title="上一章"><span class="section-number">7. </span>扩展 Distutils</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="apiref.html"
title="下一章"><span class="section-number">9. </span>API参考引用</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/commandref.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="apiref.html" title="9. API参考引用"
>下一页</a> |</li>
<li class="right" >
<a href="extending.html" title="7. 扩展 Distutils"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,321 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>3. 编写设置脚本的配置文件 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="4. 创建源代码分发包" href="sourcedist.html" />
<link rel="prev" title="2. 编写安装脚本" href="setupscript.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/configfile.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h4>上一个主题</h4>
<p class="topless"><a href="setupscript.html"
title="上一章"><span class="section-number">2. </span>编写安装脚本</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="sourcedist.html"
title="下一章"><span class="section-number">4. </span>创建源代码分发包</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/configfile.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/configfile.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="sourcedist.html" title="4. 创建源代码分发包"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="setupscript.html" title="2. 编写安装脚本"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="writing-the-setup-configuration-file">
<span id="setup-config"></span><h1><span class="section-number">3. </span>编写设置脚本的配置文件<a class="headerlink" href="#writing-the-setup-configuration-file" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档只有在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之前,才会单独保留。</p>
</div>
<p>通常,在 <em>事前</em> 就写出构建发布包所需的一切是不可能的:你可能需要从用户或者用户的系统获取一些信息,才能继续下去。 只要这些信息相当简单 —— 例如一个用于搜索 C 头文件或库的目录列表 —— 那么提供配置文件 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> 供用户配置就是一个低成本且方便的解决方式。 配置文件还允许你为任何命令选项提供默认值,而安装器可以通过命令行或编辑配置文件来覆盖这些默认值。</p>
<p>安装配置文件是在安装脚本和安装脚本命令行之间一个适当的折衷方式 --- 安装脚本在理想情况下应当不受安装者的控制 <a class="footnote-reference brackets" href="#id2" id="id1">1</a> --- 而安装脚本命令行则在你的控制范围之外且完全取决于安装者的选择。 实际上,<code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> (以及目标系统上的其他任何 Distutils 配置文件) 是在配置脚本之后、命令行之前被处理。 这导致了几个有用的后果:</p>
<ul class="simple">
<li><p>安装者可以通过编辑 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> 来覆盖你放在 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 中的配置</p></li>
<li><p>你可以为无法在 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 中方便设置的选项提供非标准的默认值</p></li>
<li><p>安装者可以使用 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 的命令行选项来覆盖 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> 中的一切</p></li>
</ul>
<p>配置文件的基本语法很简单:</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[command]</span>
<span class="na">option</span><span class="o">=</span><span class="s">value</span>
<span class="na">...</span>
</pre></div>
</div>
<p>其中 <em>command</em> 是一个 Distutils 命令 (例如 <strong class="command">build_py</strong>, <strong class="command">install</strong>),而 <em>option</em> 是该命令所支持的某个选项。 可以为每个命令提供任意数量的选项,并且可以在文件中包括任意数量的命令组。 空白行会被忽略,以一个 <code class="docutils literal notranslate"><span class="pre">'#'</span></code> 开始的注释行也是如此。 长选项值可以简单地通过缩进后续行的方式被拆分为多行。</p>
<p>你可以用通用的 <code class="xref std std-option docutils literal notranslate"><span class="pre">--help</span></code> 选项找出特定命令所支持的选项列表,例如</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>setup.py<span class="w"> </span>--help<span class="w"> </span>build_ext
<span class="go">[...]</span>
<span class="go">Options for &#39;build_ext&#39; command:</span>
<span class="go"> --build-lib (-b) directory for compiled extension modules</span>
<span class="go"> --build-temp (-t) directory for temporary files (build by-products)</span>
<span class="go"> --inplace (-i) ignore build-lib and put compiled extensions into the</span>
<span class="go"> source directory alongside your pure Python modules</span>
<span class="go"> --include-dirs (-I) list of directories to search for header files</span>
<span class="go"> --define (-D) C preprocessor macros to define</span>
<span class="go"> --undef (-U) C preprocessor macros to undefine</span>
<span class="go"> --swig-opts list of SWIG command line options</span>
<span class="go">[...]</span>
</pre></div>
</div>
<p>请注意在命令行中拼写为 <code class="xref std std-option docutils literal notranslate"><span class="pre">--foo-bar</span></code> 的选项在配置文件中会拼写为 <code class="docutils literal notranslate"><span class="pre">foo_bar</span></code></p>
<p id="distutils-build-ext-inplace">例如,假设你希望你的扩展在“原地”构建 --- 就是说你有一个扩展 <code class="xref py py-mod docutils literal notranslate"><span class="pre">pkg.ext</span></code>,你希望编译出的扩展文件 (例如在 Unix 上为 <code class="file docutils literal notranslate"><span class="pre">ext.so</span></code>) 放在与你的纯 Python 模块 <code class="xref py py-mod docutils literal notranslate"><span class="pre">pkg.mod1</span></code><code class="xref py py-mod docutils literal notranslate"><span class="pre">pkg.mod2</span></code> 相同的源目录中。 你总是可以在命令行中使用 <code class="xref std std-option docutils literal notranslate"><span class="pre">--inplace</span></code> 选项来确保这一点:</p>
<div class="highlight-sh notranslate"><div class="highlight"><pre><span></span>python<span class="w"> </span>setup.py<span class="w"> </span>build_ext<span class="w"> </span>--inplace
</pre></div>
</div>
<p>但是这要求你总是显式地指定 <strong class="command">build_ext</strong> 命令,并且记得提供 <code class="xref std std-option docutils literal notranslate"><span class="pre">--inplace</span></code>。 一个更容易的方式是通过将其编码在此发布包的配置文件 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> 中,“设置并忘记”该选项。</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[build_ext]</span>
<span class="na">inplace</span><span class="o">=</span><span class="s">1</span>
</pre></div>
</div>
<p>这将影响此模块发布包的所有构建,不论你是否显式指定 <strong class="command">build_ext</strong>。 如果你在你的源发布包中包括了 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code>,它还将影响最终用户的构建 --- 对此选项来说这可能不是个好主意,因为总是原地构建扩展会破坏模块发布包的安装。 不过在某些特殊情况下,模块是在其安装目录中被构建的,因此这可能会是个有用的功能。 (但是,发布预期在其安装目录中被构建的扩展几乎总是一个坏主意。)</p>
<p>另一个例子:特定的命令会接受许多在多次运行中都不发生变化的选项;例如,<strong class="command">bdist_rpm</strong> 需要知道为创建 RPM 发布包生成 &quot;spec&quot; 文件所要求的所有信息。 这些信息有的来自安装脚本,有的由 Distutils 自动生成(例如已安装文件列表)。 但有的则必须作为 <strong class="command">bdist_rpm</strong> 的选项提供,每次运行时都在命令行中完成将会非常繁琐。 因此,这里提供 Distutils 本身的 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> 中的一段代码:</p>
<div class="highlight-ini notranslate"><div class="highlight"><pre><span></span><span class="k">[bdist_rpm]</span>
<span class="na">release</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">1</span>
<span class="na">packager</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">Greg Ward &lt;gward@python.net&gt;</span>
<span class="na">doc_files</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="s">CHANGES.txt</span>
<span class="w"> </span><span class="na">README.txt</span>
<span class="w"> </span><span class="na">USAGE.txt</span>
<span class="w"> </span><span class="na">doc/</span>
<span class="w"> </span><span class="na">examples/</span>
</pre></div>
</div>
<p>请注意 <code class="docutils literal notranslate"><span class="pre">doc_files</span></code> 选项只是一个空格分隔以提高可读性的多行字符串。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt>&quot;安装 Python 模块&quot; 中的 <a class="reference internal" href="../install/index.html#inst-config-syntax"><span class="std std-ref">Syntax of config files</span></a></dt><dd><p>有关配置文件的更多信息可在系统管理员手册中查看。</p>
</dd>
</dl>
</div>
<p class="rubric">备注</p>
<dl class="footnote brackets">
<dt class="label" id="id2"><span class="brackets"><a class="fn-backref" href="#id1">1</a></span></dt>
<dd><p>在 Distutils 完全支持自动配置之前,这一理想可能是无法实现的。</p>
</dd>
</dl>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>上一个主题</h4>
<p class="topless"><a href="setupscript.html"
title="上一章"><span class="section-number">2. </span>编写安装脚本</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="sourcedist.html"
title="下一章"><span class="section-number">4. </span>创建源代码分发包</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/configfile.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="sourcedist.html" title="4. 创建源代码分发包"
>下一页</a> |</li>
<li class="right" >
<a href="setupscript.html" title="2. 编写安装脚本"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,522 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>6. Distutils 示例 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="7. 扩展 Distutils" href="extending.html" />
<link rel="prev" title="5. 创建构建分发版" href="builtdist.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/examples.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">6. Distutils 示例</a><ul>
<li><a class="reference internal" href="#pure-python-distribution-by-module">6.1. 纯 Python 分发(通过 module</a></li>
<li><a class="reference internal" href="#pure-python-distribution-by-package">6.2. 纯 Python 分发(通过 包)</a></li>
<li><a class="reference internal" href="#single-extension-module">6.3. 单个扩展模块</a></li>
<li><a class="reference internal" href="#checking-a-package">6.4. 检查一个包</a></li>
<li><a class="reference internal" href="#reading-the-metadata">6.5. 读取元数据</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="builtdist.html"
title="上一章"><span class="section-number">5. </span>创建构建分发版</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="extending.html"
title="下一章"><span class="section-number">7. </span>扩展 Distutils</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/examples.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/examples.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="extending.html" title="7. 扩展 Distutils"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="builtdist.html" title="5. 创建构建分发版"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="distutils-examples">
<span id="id1"></span><h1><span class="section-number">6. </span>Distutils 示例<a class="headerlink" href="#distutils-examples" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档只有在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之前,才会单独保留。</p>
</div>
<p>本章节提供几个基础示例,来帮助用户入门 distutils。关于使用 distutils 的额外信息可以参考 Distutils Cookbook。</p>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><a class="reference external" href="https://wiki.python.org/moin/Distutils/Cookbook">Distutils Cookbook</a></dt><dd><p>一套展示如何更好地控制和使用 distutils 的方法。</p>
</dd>
</dl>
</div>
<section id="pure-python-distribution-by-module">
<span id="pure-mod"></span><h2><span class="section-number">6.1. </span>纯 Python 分发(通过 module<a class="headerlink" href="#pure-python-distribution-by-module" title="永久链接至标题"></a></h2>
<p>如果你要分发一组模块,特别是它们不在特定的包中,你可以在配置脚本中使用 <code class="docutils literal notranslate"><span class="pre">py_modules</span></code> 选项单独指定它们。</p>
<p>最简单的情况下,你只用关心两个文件:一个配置脚本,和单个你要分发的模块,这个示例中的 <code class="file docutils literal notranslate"><span class="pre">foo.py</span></code>: </p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">foo</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>(在本章节的所有图中,<em>&lt;root&gt;</em> 表示分发根目录。)这种情况下的一个最小配置脚本是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">py_modules</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foo&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>注意分发的包名用 <code class="docutils literal notranslate"><span class="pre">name</span></code> 选项单独指定,没有规定它必须和包中单独的模块同名(虽然这也是个可以遵循的好习惯)。然而,分发名用来生成文件名,所以你应该坚持用字母、数字、下划线和连词号。</p>
<p>因为 <code class="docutils literal notranslate"><span class="pre">py_modules</span></code> 是个列表,你当然可以指定多个模块,比如,如果你要分发模块 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code><code class="xref py py-mod docutils literal notranslate"><span class="pre">bar</span></code>,你的配置可能是这样:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">foo</span><span class="o">.</span><span class="n">py</span>
<span class="n">bar</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>并且配置脚本是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">py_modules</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="s1">&#39;bar&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>你可以把模块源文件放进另一个目录,但是如果你有足够的模块,也许用包指定模块更简单,而不是单独列出它们。</p>
</section>
<section id="pure-python-distribution-by-package">
<span id="pure-pkg"></span><h2><span class="section-number">6.2. </span>纯 Python 分发(通过 包)<a class="headerlink" href="#pure-python-distribution-by-package" title="永久链接至标题"></a></h2>
<p>如果你有超过一组模块要分发,特别是它们在不同的包中,也许指定整个包更简单,而不是指定单独的模块。这样即使你的模块不在一个包中也有效;你可以直接令 Distutils 来从根包来处理模块,并且这样对任何其他包也有效(除非你不需要 <code class="file docutils literal notranslate"><span class="pre">__init__.py</span></code> 文件)。</p>
<p>上一个示例的配置脚本也可以写成:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>(空字符串表示根包。)</p>
<p>如果两个文件移动到子目录,但是依然在根包中,如:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">src</span><span class="o">/</span> <span class="n">foo</span><span class="o">.</span><span class="n">py</span>
<span class="n">bar</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>那么你依然需要指定根包,但是你还需要告诉 Distutils 根包中的源文件在哪:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">package_dir</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;&#39;</span><span class="p">:</span> <span class="s1">&#39;src&#39;</span><span class="p">},</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>更一般地,你要分发多个在同一个包(或者子包)中的模块。举个例子,假设 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code><code class="xref py py-mod docutils literal notranslate"><span class="pre">bar</span></code> 模块属于 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foobar</span></code> 包,排布源文件树的一种方式是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">foobar</span><span class="o">/</span>
<span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
<span class="n">foo</span><span class="o">.</span><span class="n">py</span>
<span class="n">bar</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>这其实是 Distutils 默认的排布,也是你的配置脚本中需要的工作量最小的。</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foobar&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>如果你要把模块放到没有按照它们的包名命名的目录里,那你需要再次使用 <code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 选项。比如,如果 <code class="file docutils literal notranslate"><span class="pre">src</span></code> 目录包含包 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foobar</span></code> 中的模块:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">src</span><span class="o">/</span>
<span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
<span class="n">foo</span><span class="o">.</span><span class="n">py</span>
<span class="n">bar</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>一个合适的配置脚本可以是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">package_dir</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;foobar&#39;</span><span class="p">:</span> <span class="s1">&#39;src&#39;</span><span class="p">},</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foobar&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>或者,你可以把主包中的模块直接放到分发根目录:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
<span class="n">foo</span><span class="o">.</span><span class="n">py</span>
<span class="n">bar</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>这样你的配置文件是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">package_dir</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;foobar&#39;</span><span class="p">:</span> <span class="s1">&#39;&#39;</span><span class="p">},</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foobar&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>(空字符串同样表示当前目录。)</p>
<p>如果你有子包,则它们必须显式列在 <code class="docutils literal notranslate"><span class="pre">packages</span></code> 中,但是 <code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 中的任何条目会自动扩展到子包。也就是说Distutils <em>不会</em> 扫描你的源码树,而是尝试通过查找 <code class="file docutils literal notranslate"><span class="pre">__init__.py</span></code> 文件,来弄清哪些目录与 Python 包关联。)这样,如果默认排布产生一个子包:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">foobar</span><span class="o">/</span>
<span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
<span class="n">foo</span><span class="o">.</span><span class="n">py</span>
<span class="n">bar</span><span class="o">.</span><span class="n">py</span>
<span class="n">subfoo</span><span class="o">/</span>
<span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
<span class="n">blah</span><span class="o">.</span><span class="n">py</span>
</pre></div>
</div>
<p>则相应的配置脚本是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span> <span class="s1">&#39;foobar.subfoo&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
</section>
<section id="single-extension-module">
<span id="single-ext"></span><h2><span class="section-number">6.3. </span>单个扩展模块<a class="headerlink" href="#single-extension-module" title="永久链接至标题"></a></h2>
<p>扩展模块用 <code class="docutils literal notranslate"><span class="pre">ext_modules</span></code> 选项指定。<code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 对在哪寻找扩展源文件无效;它只对纯 Python 模块的源文件有效。最简单的一个用单个C源文件写的单扩展模块是</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span><span class="n">root</span><span class="o">&gt;/</span>
<span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">foo</span><span class="o">.</span><span class="n">c</span>
</pre></div>
</div>
<p>如果 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code> 扩展属于根包,则配置脚本可以是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="kn">from</span> <span class="nn">distutils.extension</span> <span class="kn">import</span> <span class="n">Extension</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">ext_modules</span><span class="o">=</span><span class="p">[</span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.c&#39;</span><span class="p">])],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>如果扩展在包中,比如 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foopkg</span></code>,那么</p>
<p>使用完全相同的源文件树排布,通过改变扩展的名字,这个扩展很容易放入 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foopkg</span></code> 包中:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="kn">from</span> <span class="nn">distutils.extension</span> <span class="kn">import</span> <span class="n">Extension</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">ext_modules</span><span class="o">=</span><span class="p">[</span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foopkg.foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.c&#39;</span><span class="p">])],</span>
<span class="p">)</span>
</pre></div>
</div>
</section>
<section id="checking-a-package">
<h2><span class="section-number">6.4. </span>检查一个包<a class="headerlink" href="#checking-a-package" title="永久链接至标题"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">check</span></code> 命令允许你校验你的包的元数据是否满足生成分发的最低要求。</p>
<p>直接使用你的 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 脚本来运行它。如果缺了一些东西,<code class="docutils literal notranslate"><span class="pre">check</span></code> 会显示警告。</p>
<p>我们来用单个脚本举例:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">)</span>
</pre></div>
</div>
<p>运行 <code class="docutils literal notranslate"><span class="pre">check</span></code> 命令会显示一些警告:</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>setup.py<span class="w"> </span>check
<span class="go">running check</span>
<span class="go">warning: check: missing required meta-data: version, url</span>
<span class="go">warning: check: missing meta-data: either (author and author_email) or</span>
<span class="go"> (maintainer and maintainer_email) must be supplied</span>
</pre></div>
</div>
<p>如果你在 <code class="docutils literal notranslate"><span class="pre">long_description</span></code> 域中使用 reStructuredText 语法,并且安装了 <a class="reference external" href="http://docutils.sourceforge.net">docutils</a> ,你可以用 <code class="docutils literal notranslate"><span class="pre">check</span></code> 命令,和 <code class="docutils literal notranslate"><span class="pre">restructuredtext</span></code> 选项检查语法是否正确。</p>
<p>比如,如果 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 脚本改成:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">desc</span> <span class="o">=</span> <span class="s2">&quot;&quot;&quot;</span><span class="se">\</span>
<span class="s2">My description</span>
<span class="s2">==============</span>
<span class="s2">This is the description of the ``foobar`` package.</span>
<span class="s2">&quot;&quot;&quot;</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foobar&#39;</span><span class="p">,</span> <span class="n">version</span><span class="o">=</span><span class="s1">&#39;1&#39;</span><span class="p">,</span> <span class="n">author</span><span class="o">=</span><span class="s1">&#39;tarek&#39;</span><span class="p">,</span>
<span class="n">author_email</span><span class="o">=</span><span class="s1">&#39;tarek@ziade.org&#39;</span><span class="p">,</span>
<span class="n">url</span><span class="o">=</span><span class="s1">&#39;http://example.com&#39;</span><span class="p">,</span> <span class="n">long_description</span><span class="o">=</span><span class="n">desc</span><span class="p">)</span>
</pre></div>
</div>
<p>长描述中有问题的地方,通过使用 <code class="xref py py-mod docutils literal notranslate"><span class="pre">docutils</span></code> 解析器,<code class="docutils literal notranslate"><span class="pre">check</span></code> 能进行删除:</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>setup.py<span class="w"> </span>check<span class="w"> </span>--restructuredtext
<span class="go">running check</span>
<span class="go">warning: check: Title underline too short. (line 2)</span>
<span class="go">warning: check: Could not finish the parsing.</span>
</pre></div>
</div>
</section>
<section id="reading-the-metadata">
<h2><span class="section-number">6.5. </span>读取元数据<a class="headerlink" href="#reading-the-metadata" title="永久链接至标题"></a></h2>
<p><a class="reference internal" href="apiref.html#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.core.setup()</span></code></a> 函数提供一个通过项目的 <code class="docutils literal notranslate"><span class="pre">setup.py</span></code> 脚本,来查询项目的元数据的域的命令行接口:</p>
<div class="highlight-shell-session notranslate"><div class="highlight"><pre><span></span><span class="gp">$ </span>python<span class="w"> </span>setup.py<span class="w"> </span>--name
<span class="go">distribute</span>
</pre></div>
</div>
<p>这个调用通过运行 <a class="reference internal" href="apiref.html#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.core.setup()</span></code></a> 函数读取 <code class="docutils literal notranslate"><span class="pre">name</span></code> 元数据。然而,当源文件或者二进制分发用 Distutils 创建时,元数据域写入一个名为 <code class="file docutils literal notranslate"><span class="pre">PKG-INFO</span></code> 的静态文件。当一个基于Distutils的项目安装在 Python 中时,<code class="file docutils literal notranslate"><span class="pre">PKG-INFO</span></code> 文件随着分发的模块和包一起复制到 <code class="file docutils literal notranslate"><span class="pre">NAME-VERSION-pyX.X.egg-info</span></code> 中,其中 <code class="docutils literal notranslate"><span class="pre">NAME</span></code> 是项目的名字,<code class="docutils literal notranslate"><span class="pre">VERSION</span></code> 是元数据中定义的版本, <code class="docutils literal notranslate"><span class="pre">pyX.X</span></code> 则是 Python 的大版本和小版本,如 <code class="docutils literal notranslate"><span class="pre">2.7</span></code> 或者 <code class="docutils literal notranslate"><span class="pre">3.2</span></code></p>
<p>你可以读回静态文件,使用 <code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.dist.DistributionMetadata</span></code> 类和它的 <code class="xref py py-func docutils literal notranslate"><span class="pre">read_pkg_file()</span></code> 方法:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">distutils.dist</span> <span class="kn">import</span> <span class="n">DistributionMetadata</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">metadata</span> <span class="o">=</span> <span class="n">DistributionMetadata</span><span class="p">()</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">metadata</span><span class="o">.</span><span class="n">read_pkg_file</span><span class="p">(</span><span class="nb">open</span><span class="p">(</span><span class="s1">&#39;distribute-0.6.8-py2.7.egg-info&#39;</span><span class="p">))</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">metadata</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;distribute&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">metadata</span><span class="o">.</span><span class="n">version</span>
<span class="go">&#39;0.6.8&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">metadata</span><span class="o">.</span><span class="n">description</span>
<span class="go">&#39;Easily download, build, install, upgrade, and uninstall Python packages&#39;</span>
</pre></div>
</div>
<p>注意类也可以用元数据文件载入值来实例化:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">pkg_info_path</span> <span class="o">=</span> <span class="s1">&#39;distribute-0.6.8-py2.7.egg-info&#39;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">DistributionMetadata</span><span class="p">(</span><span class="n">pkg_info_path</span><span class="p">)</span><span class="o">.</span><span class="n">name</span>
<span class="go">&#39;distribute&#39;</span>
</pre></div>
</div>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">6. Distutils 示例</a><ul>
<li><a class="reference internal" href="#pure-python-distribution-by-module">6.1. 纯 Python 分发(通过 module</a></li>
<li><a class="reference internal" href="#pure-python-distribution-by-package">6.2. 纯 Python 分发(通过 包)</a></li>
<li><a class="reference internal" href="#single-extension-module">6.3. 单个扩展模块</a></li>
<li><a class="reference internal" href="#checking-a-package">6.4. 检查一个包</a></li>
<li><a class="reference internal" href="#reading-the-metadata">6.5. 读取元数据</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="builtdist.html"
title="上一章"><span class="section-number">5. </span>创建构建分发版</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="extending.html"
title="下一章"><span class="section-number">7. </span>扩展 Distutils</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/examples.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="extending.html" title="7. 扩展 Distutils"
>下一页</a> |</li>
<li class="right" >
<a href="builtdist.html" title="5. 创建构建分发版"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,301 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>7. 扩展 Distutils &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="8. 命令参考" href="commandref.html" />
<link rel="prev" title="6. Distutils 示例" href="examples.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/extending.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">7. 扩展 Distutils</a><ul>
<li><a class="reference internal" href="#integrating-new-commands">7.1. 集成新的命令</a></li>
<li><a class="reference internal" href="#adding-new-distribution-types">7.2. 添加新的发布类型</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="examples.html"
title="上一章"><span class="section-number">6. </span>Distutils 示例</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="commandref.html"
title="下一章"><span class="section-number">8. </span>命令参考</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/extending.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/extending.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="commandref.html" title="8. 命令参考"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="examples.html" title="6. Distutils 示例"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="extending-distutils">
<span id="id1"></span><h1><span class="section-number">7. </span>扩展 Distutils<a class="headerlink" href="#extending-distutils" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档只有在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之前,才会单独保留。</p>
</div>
<p>Distutils 可以通过各种方式扩展。 大多数扩展都采用新命令或现有命令的替换形式。 例如,可以编写新命令以支持新的特定于平台的包格式,但是可以修改现有命令的替换,以修改命令在包上的操作细节。</p>
<p>distutils 的大多数扩展都在想要修改现有命令的 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 脚本中编写;其中许多只是简单地在 <code class="file docutils literal notranslate"><span class="pre">.py</span></code> 文件以外添加了一些应当被拷贝到包中的文件后缀以便使用。</p>
<p>大多部 distutils 命令的实现都是 <a class="reference internal" href="apiref.html#distutils.cmd.Command" title="distutils.cmd.Command"><code class="xref py py-class docutils literal notranslate"><span class="pre">distutils.cmd.Command</span></code></a> 类的子类。 新增命令可直接继承自 <code class="xref py py-class docutils literal notranslate"><span class="pre">Command</span></code>,而替换命令往往间接派生自 <code class="xref py py-class docutils literal notranslate"><span class="pre">Command</span></code> 直接子类化它们所替换的命令。 所有命令都要求自 <code class="xref py py-class docutils literal notranslate"><span class="pre">Command</span></code> 派生。</p>
<section id="integrating-new-commands">
<h2><span class="section-number">7.1. </span>集成新的命令<a class="headerlink" href="#integrating-new-commands" title="永久链接至标题"></a></h2>
<p>有多种方法可将新的命令实现集成到 distutils 中。 最困难的一种是鼓动在 distutils 自身内部包含新特性,并等待(以及要求)某个 Python 版本提供该支持。 出于多种原因,这确实是相当难的。</p>
<p>对于大多数需求来说最为常见并且可能最为合理的一种则是通过你自己的 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 脚本来包含新的实现,然后让 <a class="reference internal" href="apiref.html#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.core.setup()</span></code></a> 函数使用它们:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.command.build_py</span> <span class="kn">import</span> <span class="n">build_py</span> <span class="k">as</span> <span class="n">_build_py</span>
<span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="k">class</span> <span class="nc">build_py</span><span class="p">(</span><span class="n">_build_py</span><span class="p">):</span>
<span class="w"> </span><span class="sd">&quot;&quot;&quot;Specialized Python source builder.&quot;&quot;&quot;</span>
<span class="c1"># implement whatever needs to be different...</span>
<span class="n">setup</span><span class="p">(</span><span class="n">cmdclass</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;build_py&#39;</span><span class="p">:</span> <span class="n">build_py</span><span class="p">},</span>
<span class="o">...</span><span class="p">)</span>
</pre></div>
</div>
<p>如果新的实现必须通过特定的包来使用则此方式最为适宜,因为每个对这个包感兴趣的人都将会需要有新的命令实现。</p>
<p>从 Python 2.4 开始,还有第三个选项可用,其目标是允许添加支持现有 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 脚本的新命令,而不需要修改 Python 安装包。 这预计可允许第三方扩展提供对附加打包系统的支持,而相应命令又可用于任何 distutils 命令可被使用的地方。 新的配置选项 <code class="docutils literal notranslate"><span class="pre">command_packages</span></code> (命令行选项为 <code class="xref std std-option docutils literal notranslate"><span class="pre">--command-packages</span></code>) 可用来指定附加包,以在其中查找实现新增命令的模块。 像所有 distutils 选项一样,这可以通过命令行或配置文件来指定。 此选项只能在配置文件的 <code class="docutils literal notranslate"><span class="pre">[global]</span></code> 小节之中或在命令行的任何命令之前设置。 如果是设置在配置文件中,则它可被命令行设置重载;如果在命令行中将其设为空字符串则将会使用默认值。 此选项绝不应当在随特定包提供的配置文件中设置。</p>
<p>这个新选项可被用来添加任意数量的包到查找命令实现的包列表;多个包名应当以逗号分隔。 当未指明时,查找将只在 <a class="reference internal" href="apiref.html#module-distutils.command" title="distutils.command: Contains one module for each standard Distutils command."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command</span></code></a> 包中进行。 但是当 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 附带 <code class="docutils literal notranslate"><span class="pre">--command-packages</span> <span class="pre">distcmds,buildcmds</span></code> 选项运行时,<a class="reference internal" href="apiref.html#module-distutils.command" title="distutils.command: Contains one module for each standard Distutils command."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command</span></code></a>, <code class="xref py py-mod docutils literal notranslate"><span class="pre">distcmds</span></code><code class="xref py py-mod docutils literal notranslate"><span class="pre">buildcmds</span></code> 包将按此顺序被查找。 新的命令应当在与命名同名的模块中由同名的类来实现。 给定上述示例命令行选项,则命令 <strong class="command">bdist_openpkg</strong> 可由类 <code class="xref py py-class docutils literal notranslate"><span class="pre">distcmds.bdist_openpkg.bdist_openpkg</span></code><code class="xref py py-class docutils literal notranslate"><span class="pre">buildcmds.bdist_openpkg.bdist_openpkg</span></code> 来实现。</p>
</section>
<section id="adding-new-distribution-types">
<h2><span class="section-number">7.2. </span>添加新的发布类型<a class="headerlink" href="#adding-new-distribution-types" title="永久链接至标题"></a></h2>
<p>创建发布(在 <code class="file docutils literal notranslate"><span class="pre">dist/</span></code> 目录中的文件)的命令需要将 <code class="docutils literal notranslate"><span class="pre">(command,</span> <span class="pre">filename)</span></code> 二元组添加到 <code class="docutils literal notranslate"><span class="pre">self.distribution.dist_files</span></code> 以便 <strong class="command">upload</strong> 可以将其上传到 PyPI。 二元组中的 <em>filename</em> 不包含路径信息而只有文件名本身。 在 dry-run 模式下,二元组仍然应当被添加以表示必须创建的内容。</p>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">7. 扩展 Distutils</a><ul>
<li><a class="reference internal" href="#integrating-new-commands">7.1. 集成新的命令</a></li>
<li><a class="reference internal" href="#adding-new-distribution-types">7.2. 添加新的发布类型</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="examples.html"
title="上一章"><span class="section-number">6. </span>Distutils 示例</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="commandref.html"
title="下一章"><span class="section-number">8. </span>命令参考</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/extending.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="commandref.html" title="8. 命令参考"
>下一页</a> |</li>
<li class="right" >
<a href="examples.html" title="6. Distutils 示例"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,377 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>分发 Python 模块(遗留版本) &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="1. Distutils 模块介绍" href="introduction.html" />
<link rel="prev" title="历史和许可证" href="../license.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/index.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h4>上一个主题</h4>
<p class="topless"><a href="../license.html"
title="上一章">历史和许可证</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="introduction.html"
title="下一章"><span class="section-number">1. </span>Distutils 模块介绍</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/index.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/index.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="introduction.html" title="1. Distutils 模块介绍"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="../license.html" title="历史和许可证"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="distributing-python-modules-legacy-version">
<span id="distutils-index"></span><h1>分发 Python 模块(遗留版本)<a class="headerlink" href="#distributing-python-modules-legacy-version" title="永久链接至标题"></a></h1>
<dl class="field-list simple">
<dt class="field-odd">作者</dt>
<dd class="field-odd"><p>Greg Ward Anthony Baxter</p>
</dd>
<dt class="field-even">电子邮箱</dt>
<dd class="field-even"><p><a class="reference external" href="mailto:distutils-sig&#37;&#52;&#48;python&#46;org">distutils-sig<span>&#64;</span>python<span>&#46;</span>org</a></p>
</dd>
</dl>
<div class="admonition seealso">
<p class="admonition-title">参见</p>
<dl class="simple">
<dt><a class="reference internal" href="../distributing/index.html#distributing-index"><span class="std std-ref">分发 Python 模块</span></a></dt><dd><p>最新的模块分发文档</p>
</dd>
</dl>
</div>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档只有在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之前,才会单独保留。</p>
</div>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>本指南仅介绍构建和分发扩展的基本工具这些扩展是作为此Python版本的一部分提供的。 第三方工具提供更易于使用和更安全的替代方案。有关详细信息,请参阅 Python 打包用户指南中的 <a class="reference external" href="https://packaging.python.org/guides/tool-recommendations/">快速推荐部分</a></p>
</div>
<p>本文档从模块开发人员的角度描述了 Python Distribution Utilities (&quot;Distutils&quot;)。 描述了 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 构建所依赖的下层功能,以允许 Python 开发者方便地为更广泛的受众编写 Python 模块和扩展。</p>
<div class="toctree-wrapper compound">
<ul>
<li class="toctree-l1"><a class="reference internal" href="introduction.html">1. Distutils 模块介绍</a><ul>
<li class="toctree-l2"><a class="reference internal" href="introduction.html#concepts-terminology">1.1. 概念和术语</a></li>
<li class="toctree-l2"><a class="reference internal" href="introduction.html#a-simple-example">1.2. 一个简单的例子</a></li>
<li class="toctree-l2"><a class="reference internal" href="introduction.html#general-python-terminology">1.3. 通用的 Python 术语</a></li>
<li class="toctree-l2"><a class="reference internal" href="introduction.html#distutils-specific-terminology">1.4. Distutils 特定的术语</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="setupscript.html">2. 编写安装脚本</a><ul>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#listing-whole-packages">2.1. 列出全部的包</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#listing-individual-modules">2.2. 列出单独的模块</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#describing-extension-modules">2.3. 描述扩展模块</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#relationships-between-distributions-and-packages">2.4. 分发和软件包之间的关系</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#installing-scripts">2.5. 安装脚本</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#installing-package-data">2.6. 安装软件包数据</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#installing-additional-files">2.7. 安装其它文件</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#additional-meta-data">2.8. 附加元数据</a></li>
<li class="toctree-l2"><a class="reference internal" href="setupscript.html#debugging-the-setup-script">2.9. 调试安装脚本</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="configfile.html">3. 编写设置脚本的配置文件</a></li>
<li class="toctree-l1"><a class="reference internal" href="sourcedist.html">4. 创建源代码分发包</a><ul>
<li class="toctree-l2"><a class="reference internal" href="sourcedist.html#specifying-the-files-to-distribute">4.1. 指定要分发的文件</a></li>
<li class="toctree-l2"><a class="reference internal" href="sourcedist.html#manifest-related-options">4.2. 声明相关选项</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="builtdist.html">5. 创建构建分发版</a><ul>
<li class="toctree-l2"><a class="reference internal" href="builtdist.html#creating-rpm-packages">5.1. 创建RPM软件包</a></li>
<li class="toctree-l2"><a class="reference internal" href="builtdist.html#creating-windows-installers">5.2. Creating Windows Installers</a></li>
<li class="toctree-l2"><a class="reference internal" href="builtdist.html#cross-compiling-on-windows">5.3. 在 Windows 上的交叉编译</a></li>
<li class="toctree-l2"><a class="reference internal" href="builtdist.html#vista-user-access-control-uac">5.4. Vista User Access Control (UAC)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="examples.html">6. Distutils 示例</a><ul>
<li class="toctree-l2"><a class="reference internal" href="examples.html#pure-python-distribution-by-module">6.1. 纯 Python 分发(通过 module</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#pure-python-distribution-by-package">6.2. 纯 Python 分发(通过 包)</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#single-extension-module">6.3. 单个扩展模块</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#checking-a-package">6.4. 检查一个包</a></li>
<li class="toctree-l2"><a class="reference internal" href="examples.html#reading-the-metadata">6.5. 读取元数据</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="extending.html">7. 扩展 Distutils</a><ul>
<li class="toctree-l2"><a class="reference internal" href="extending.html#integrating-new-commands">7.1. 集成新的命令</a></li>
<li class="toctree-l2"><a class="reference internal" href="extending.html#adding-new-distribution-types">7.2. 添加新的发布类型</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="commandref.html">8. 命令参考</a><ul>
<li class="toctree-l2"><a class="reference internal" href="commandref.html#installing-modules-the-install-command-family">8.1. 安装模块: <strong class="command">install</strong> 命令族</a></li>
<li class="toctree-l2"><a class="reference internal" href="commandref.html#creating-a-source-distribution-the-sdist-command">8.2. 创建源码发行包: <strong class="command">sdist</strong> 命令</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="apiref.html">9. API参考引用</a><ul>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.core">9.1. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.core</span></code> --- 分发包功能的核心</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.ccompiler">9.2. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.ccompiler</span></code> --- CCompiler基类</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.unixccompiler">9.3. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.unixccompiler</span></code> --- Unix C Compiler</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.msvccompiler">9.4. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.msvccompiler</span></code> --- Microsoft Compiler</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.bcppcompiler">9.5. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.bcppcompiler</span></code> --- Borland Compiler</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.cygwinccompiler">9.6. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.cygwincompiler</span></code> --- Cygwin Compiler</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.archive_util">9.7. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.archive_util</span></code> --- Archiving utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.dep_util">9.8. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.dep_util</span></code> --- Dependency checking</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.dir_util">9.9. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.dir_util</span></code> --- Directory tree operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.file_util">9.10. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.file_util</span></code> --- Single file operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.util">9.11. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.util</span></code> --- Miscellaneous other utility functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.dist">9.12. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.dist</span></code> --- The Distribution class</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.extension">9.13. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.extension</span></code> --- The Extension class</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.debug">9.14. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.debug</span></code> --- Distutils debug mode</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.errors">9.15. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.errors</span></code> --- Distutils exceptions</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.fancy_getopt">9.16. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.fancy_getopt</span></code> --- Wrapper around the standard getopt module</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.filelist">9.17. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.filelist</span></code> --- The FileList class</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.log">9.18. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.log</span></code> --- Simple <strong>PEP 282</strong>-style logging</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.spawn">9.19. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.spawn</span></code> --- Spawn a sub-process</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.sysconfig">9.20. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.sysconfig</span></code> --- System configuration information</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.text_file">9.21. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.text_file</span></code> --- The TextFile class</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.version">9.22. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.version</span></code> --- Version number classes</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.cmd">9.23. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.cmd</span></code> --- Abstract base class for Distutils commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#creating-a-new-distutils-command">9.24. Creating a new Distutils command</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command">9.25. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command</span></code> --- Individual Distutils commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.bdist">9.26. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.bdist</span></code> --- Build a binary installer</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.bdist_packager">9.27. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.bdist_packager</span></code> --- Abstract base class for packagers</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.bdist_dumb">9.28. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.bdist_dumb</span></code> --- Build a &quot;dumb&quot; installer</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.bdist_msi">9.29. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.bdist_msi</span></code> --- Build a Microsoft Installer binary package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.bdist_rpm">9.30. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.bdist_rpm</span></code> --- Build a binary distribution as a Redhat RPM and SRPM</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.bdist_wininst">9.31. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.bdist_wininst</span></code> --- Build a Windows installer</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.sdist">9.32. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.sdist</span></code> --- Build a source distribution</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.build">9.33. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.build</span></code> --- Build all files of a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.build_clib">9.34. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.build_clib</span></code> --- Build any C libraries in a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.build_ext">9.35. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.build_ext</span></code> --- Build any extensions in a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.build_py">9.36. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.build_py</span></code> --- Build the .py/.pyc files of a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.build_scripts">9.37. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.build_scripts</span></code> --- Build the scripts of a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.clean">9.38. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.clean</span></code> --- Clean a package build area</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.config">9.39. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.config</span></code> --- Perform package configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.install">9.40. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.install</span></code> --- Install a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.install_data">9.41. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.install_data</span></code> --- Install data files from a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.install_headers">9.42. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.install_headers</span></code> --- Install C/C++ header files from a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.install_lib">9.43. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.install_lib</span></code> --- Install library files from a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.install_scripts">9.44. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.install_scripts</span></code> --- Install script files from a package</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.register">9.45. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.register</span></code> --- Register a module with the Python Package Index</a></li>
<li class="toctree-l2"><a class="reference internal" href="apiref.html#module-distutils.command.check">9.46. <code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.command.check</span></code> --- Check the meta-data of a package</a></li>
</ul>
</li>
</ul>
</div>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h4>上一个主题</h4>
<p class="topless"><a href="../license.html"
title="上一章">历史和许可证</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="introduction.html"
title="下一章"><span class="section-number">1. </span>Distutils 模块介绍</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/index.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="introduction.html" title="1. Distutils 模块介绍"
>下一页</a> |</li>
<li class="right" >
<a href="../license.html" title="历史和许可证"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,374 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>1. Distutils 模块介绍 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="2. 编写安装脚本" href="setupscript.html" />
<link rel="prev" title="分发 Python 模块(遗留版本)" href="index.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/introduction.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">1. Distutils 模块介绍</a><ul>
<li><a class="reference internal" href="#concepts-terminology">1.1. 概念和术语</a></li>
<li><a class="reference internal" href="#a-simple-example">1.2. 一个简单的例子</a></li>
<li><a class="reference internal" href="#general-python-terminology">1.3. 通用的 Python 术语</a></li>
<li><a class="reference internal" href="#distutils-specific-terminology">1.4. Distutils 特定的术语</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="index.html"
title="上一章">分发 Python 模块(遗留版本)</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="setupscript.html"
title="下一章"><span class="section-number">2. </span>编写安装脚本</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/introduction.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/introduction.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="setupscript.html" title="2. 编写安装脚本"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="index.html" title="分发 Python 模块(遗留版本)"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="an-introduction-to-distutils">
<span id="distutils-intro"></span><h1><span class="section-number">1. </span>Distutils 模块介绍<a class="headerlink" href="#an-introduction-to-distutils" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档是历史遗留文档,在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之后,将不再单独作为正式文档保留。</p>
</div>
<p>本文档介绍了使用 Distutils 模块分发你的 Python 模块,主要是针对开发者/分发者的使用的——如果你想了解如何安装 Python 模块,你应该参考这个章节: <a class="reference internal" href="../install/index.html#install-index"><span class="std std-ref">安装Python模块旧版</span></a></p>
<section id="concepts-terminology">
<span id="distutils-concepts"></span><h2><span class="section-number">1.1. </span>概念和术语<a class="headerlink" href="#concepts-terminology" title="永久链接至标题"></a></h2>
<p>Distutils 用起来非常简单,对于模块开发者或安装第三方模块的用户/管理员均是如此。开发者的责任(当然还有编写可靠、良好文档和经过良好测试的代码!)就是:</p>
<ul class="simple">
<li><p>编写一个设置脚本 (<code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> by convention)</p></li>
<li><p>(可选)编写设置脚本的配置文件</p></li>
<li><p>创建源码的发行版</p></li>
<li><p>(可选)创建一个或多个编译好(二进制)的发行版</p></li>
</ul>
<p>这些操作在此文档均有讲解。</p>
<p>并非所有的模块开发者都能接触到众多的平台,所以期望他们创造众多的内置发行版不是总是可行的。最好是有一类名为 <em>打包者</em> 的中介,以满足这一需求。打包者将读取模块开发者发布的源代码,在一个或多个平台上进行编译,并发布构建出来的发行版。这样,最流行平台的用户就能以最自然的方式安装最流行的 Python 模块发行版,不必运行一段 setup 脚本或编译代码了。</p>
</section>
<section id="a-simple-example">
<span id="distutils-simple-example"></span><h2><span class="section-number">1.2. </span>一个简单的例子<a class="headerlink" href="#a-simple-example" title="永久链接至标题"></a></h2>
<p>setup 脚本通常很简单,尽管是用 Python 编写的,它能干的事情没有限制,当然应小心别在 setup 脚本中加入什么运行缓慢的操作。与 Autoconf 风格的 configure 脚本不同,在构建和安装模块的过程中 setup 脚本可能会运行多次。</p>
<p>如果只想发布一个名为 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code> 的模块,位于 <code class="file docutils literal notranslate"><span class="pre">foo.py</span></code> 文件中,那么 setup 脚本可以如此简单:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">py_modules</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foo&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>注意要点:</p>
<ul class="simple">
<li><p>提供给 Distutils 的大部分信息将作为关键字参数发给 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 函数。</p></li>
<li><p>这些关键字参数分为两类:包的元数据(名称、版本号)和包中内容的描述信息(本例中是纯 Python 模块的列表)。</p></li>
<li><p>模块由模块名指定,而不是文件名(包和扩展也是如此)。</p></li>
<li><p>建议多提供一些元数据特别是开发者姓名、电子邮件地址和项目的URL参见 <a class="reference internal" href="setupscript.html#setup-script"><span class="std std-ref">编写安装脚本</span></a> 中的例子)。</p></li>
</ul>
<p>要为该模块创建一个源码发布版本,需要创建一段 setup 脚本 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code>,包含上述代码,然后从终端运行以下命令:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">sdist</span>
</pre></div>
</div>
<p>对于 Windows 用户来说,打开命令行窗口(<span class="menuselection">Start ‣ Accessories</span>)并且写上如下命令:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">sdist</span>
</pre></div>
</div>
<p><strong class="command">sdist</strong> 将创建一个归档文件(例如在 Unix 中为 tarball在 Windows 中为 ZIP 文件),其中包含你的配置脚本 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 以及你的模块 <code class="file docutils literal notranslate"><span class="pre">foo.py</span></code>。 此归档文件将被命名为 <code class="file docutils literal notranslate"><span class="pre">foo-1.0.tar.gz</span></code> (或 <code class="file docutils literal notranslate"><span class="pre">.zip</span></code>),并将解包到目录 <code class="file docutils literal notranslate"><span class="pre">foo-1.0</span></code> 当中。</p>
<p>如果最终用户希望安装 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code> 模块,只需下载 <code class="file docutils literal notranslate"><span class="pre">foo-1.0.tar.gz</span></code> (或 <code class="file docutils literal notranslate"><span class="pre">.zip</span></code> )并解压,进入 <code class="file docutils literal notranslate"><span class="pre">foo-1.0</span></code> 目录运行:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">install</span>
</pre></div>
</div>
<p>这会把 <code class="file docutils literal notranslate"><span class="pre">foo.py</span></code> 复制到 Python 安装环境的第三方模块目录中。</p>
<p>上述简单例子展示了 Distutils 的一些基本概念。首先,开发者和安装者拥有相同的基本用户界面,即 setup 脚本。区别在于使用哪种 Distutils <em>命令</em> <strong class="command">sdist</strong> 命令几乎只适用于模块开发者,而 <strong class="command">install</strong> 则更适用于安装者(当然大多数开发者偶尔也想要安装自己的代码)。</p>
<p>If you want to make things really easy for your users, you can create one or
more built distributions for them. For instance, if you are running on a
Windows machine, and want to make things easy for other Windows users, you can
create an executable installer (the most appropriate type of built distribution
for this platform) with the <strong class="command">bdist_wininst</strong> command. For example:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist_wininst</span>
</pre></div>
</div>
<p>will create an executable installer, <code class="file docutils literal notranslate"><span class="pre">foo-1.0.win32.exe</span></code>, in the current
directory.</p>
<p>其他有用的内置分发格式是 RPM可由 <strong class="command">bdist_rpm</strong> 、Solaris <strong class="program">pkgtool`:command:`bdist_pkgtool</strong>)和 HP-UX <strong class="program">swinstall`:command:`bdist_sdux</strong>)实现。比如,以下命令将创建一个名为 <code class="file docutils literal notranslate"><span class="pre">foo-1.0.noarch.rpm</span></code> 的RPM文件</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist_rpm</span>
</pre></div>
</div>
<p><strong class="command">bdist_rpm</strong> 命令用到了 <strong class="command">rpm</strong> 可执行文件,因此必须运行在基于 RPM 的系统中,如 Red Hat Linux 、 SuSE Linux 或 Mandrake Linux</p>
<p>可以随时运行以下命令,以便了解当前可用的分发格式:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">bdist</span> <span class="o">--</span><span class="n">help</span><span class="o">-</span><span class="n">formats</span>
</pre></div>
</div>
</section>
<section id="general-python-terminology">
<span id="python-terms"></span><h2><span class="section-number">1.3. </span>通用的 Python 术语<a class="headerlink" href="#general-python-terminology" title="永久链接至标题"></a></h2>
<p>本文读者可能对模块、扩展等已有了很好的理解。但为确保所有人都站在同一起点上,下面提供了 Python 常用术语表:</p>
<dl class="simple">
<dt>module</dt><dd><p>实现 Python 代码重用的基本单位:可被其他代码导入的一段代码。有三种类型的模块与本文有关:纯 Python 模块、扩展模块和包。</p>
</dd>
<dt>纯 Python 模块</dt><dd><p>用 Python 编写的模块,包含在某 <code class="file docutils literal notranslate"><span class="pre">.py</span></code> 文件中(可能还会有相关的 <code class="file docutils literal notranslate"><span class="pre">.pyc</span></code> 文件)。有时被称为 &quot;纯模块&quot;</p>
</dd>
<dt>extension module -- 扩展模块</dt><dd><p>用低级语言编写的 Python 模块。Python 用 C/C++ ,而 Jython 则用Java。通常包含在一个可动态加载的预编译文件中比如 Unix 中的 Python 扩展是一个共享对象(<code class="file docutils literal notranslate"><span class="pre">.so</span></code>文件Windows 中的 Python 扩展则是一个 DLL (扩展名为 <code class="file docutils literal notranslate"><span class="pre">.pyd</span></code> ),而 Jython 的扩展是个 Java class 文件。注意目前Distutils 只处理 Python 的 C/C++ 扩展。)</p>
</dd>
<dt></dt><dd><p>包含其他模块的模块;通常位于文件系统的某个目录中,区别于其他目录的标记就是存在一个 <code class="file docutils literal notranslate"><span class="pre">__init__.py</span></code> 文件。</p>
</dd>
<dt>根包</dt><dd><p>包的层次结构的根。(其并非一个真正的包,因为没有 <code class="file docutils literal notranslate"><span class="pre">__init__.py</span></code> 文件。但总得给它起个名字)。 绝大多数标准库都在根包中,还有许多不属于任何大型模块的小型、独立的第三方模块。与普通的包不同,根包中的模块可能会在很多目录中出现:事实上,<code class="docutils literal notranslate"><span class="pre">sys.path</span></code> 列出的每个目录都会为根包提供模块。</p>
</dd>
</dl>
</section>
<section id="distutils-specific-terminology">
<span id="distutils-term"></span><h2><span class="section-number">1.4. </span>Distutils 特定的术语<a class="headerlink" href="#distutils-specific-terminology" title="永久链接至标题"></a></h2>
<p>以下属于更加特别地用于 Distutils 发布 Python 模块。</p>
<dl class="simple">
<dt>模块发行版</dt><dd><p>一组 Python 模块,作为可下载的资源组团发布,以便 <em>大规模</em> 安装。模块发布版的著名例子是 NumPy 、 SciPy 、 Pillow 或 mxBase。这些会被称为 <em>package</em>,这个词在 Python 的语境中也使用过:一个模块发行版可能包含零个、一个或多个 Python 包。)</p>
</dd>
<dt>纯模块发行版</dt><dd><p>只包含纯 Python 模块和软件包的模块发布版。有时被称为“纯发行版”。</p>
</dd>
<dt>非纯模块发行版</dt><dd><p>至少包含一个扩展模块的模块发行版。 有时被称为“非纯发行版”。</p>
</dd>
<dt>根发行版</dt><dd><p>源代码树(或源代码发行版)的顶级目录;即 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 所在的目录。 一般来说,<code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 会在该目录下运行。</p>
</dd>
</dl>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">1. Distutils 模块介绍</a><ul>
<li><a class="reference internal" href="#concepts-terminology">1.1. 概念和术语</a></li>
<li><a class="reference internal" href="#a-simple-example">1.2. 一个简单的例子</a></li>
<li><a class="reference internal" href="#general-python-terminology">1.3. 通用的 Python 术语</a></li>
<li><a class="reference internal" href="#distutils-specific-terminology">1.4. Distutils 特定的术语</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="index.html"
title="上一章">分发 Python 模块(遗留版本)</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="setupscript.html"
title="下一章"><span class="section-number">2. </span>编写安装脚本</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/introduction.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="setupscript.html" title="2. 编写安装脚本"
>下一页</a> |</li>
<li class="right" >
<a href="index.html" title="分发 Python 模块(遗留版本)"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,226 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>Python 包索引PyPI &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/packageindex.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/packageindex.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/packageindex.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="the-python-package-index-pypi">
<span id="package-index"></span><h1>Python 包索引PyPI<a class="headerlink" href="#the-python-package-index-pypi" title="永久链接至标题"></a></h1>
<p><a class="reference external" href="https://pypi.org">Python 包索引 (PyPI)</a> 存储描述与 distutils 和其他发布工具一起打包的发行版的元数据,以及分发存档本身。</p>
<p>供参考的最新 PyPI 文档可以在 <a class="reference internal" href="../distributing/index.html#publishing-python-packages"><span class="std std-ref">阅读 Python 打包用户指南</span></a> 找到。</p>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/packageindex.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,742 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>2. 编写安装脚本 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="3. 编写设置脚本的配置文件" href="configfile.html" />
<link rel="prev" title="1. Distutils 模块介绍" href="introduction.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/setupscript.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">2. 编写安装脚本</a><ul>
<li><a class="reference internal" href="#listing-whole-packages">2.1. 列出全部的包</a></li>
<li><a class="reference internal" href="#listing-individual-modules">2.2. 列出单独的模块</a></li>
<li><a class="reference internal" href="#describing-extension-modules">2.3. 描述扩展模块</a><ul>
<li><a class="reference internal" href="#extension-names-and-packages">2.3.1. 扩展名和软件包</a></li>
<li><a class="reference internal" href="#extension-source-files">2.3.2. 扩展的源文件</a></li>
<li><a class="reference internal" href="#preprocessor-options">2.3.3. 预处理器选项</a></li>
<li><a class="reference internal" href="#library-options">2.3.4. 库选项</a></li>
<li><a class="reference internal" href="#other-options">2.3.5. 其它选项</a></li>
</ul>
</li>
<li><a class="reference internal" href="#relationships-between-distributions-and-packages">2.4. 分发和软件包之间的关系</a></li>
<li><a class="reference internal" href="#installing-scripts">2.5. 安装脚本</a></li>
<li><a class="reference internal" href="#installing-package-data">2.6. 安装软件包数据</a></li>
<li><a class="reference internal" href="#installing-additional-files">2.7. 安装其它文件</a></li>
<li><a class="reference internal" href="#additional-meta-data">2.8. 附加元数据</a></li>
<li><a class="reference internal" href="#debugging-the-setup-script">2.9. 调试安装脚本</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="introduction.html"
title="上一章"><span class="section-number">1. </span>Distutils 模块介绍</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="configfile.html"
title="下一章"><span class="section-number">3. </span>编写设置脚本的配置文件</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/setupscript.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/setupscript.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="configfile.html" title="3. 编写设置脚本的配置文件"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="introduction.html" title="1. Distutils 模块介绍"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="writing-the-setup-script">
<span id="setup-script"></span><h1><span class="section-number">2. </span>编写安装脚本<a class="headerlink" href="#writing-the-setup-script" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档是历史遗留文档,在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之后,将不再单独作为正式文档保留。</p>
</div>
<p>安装脚本是使用 Distutils 进行构建、分发和安装模块的的入口。设置脚本的主要目的是向 Distutils 描述如何分发您的模块,以便对您的模块进行操作的各种命令正确运行。正如我们在上面的 <a class="reference internal" href="introduction.html#distutils-simple-example"><span class="std std-ref">一个简单的例子</span></a> 部分中看到的,安装脚本主要包含对 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 的调用,并且模块开发人员提供给 Distutils 的大部分信息都通过关键字参数提供给 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code></p>
<p>这是一个略微复杂一点的例子我们将在接下来的几节中继续追踪它Distutils 本身的安装脚本。 (请记住,虽然 Distutils 被包括在 Python 1.6 及之后的版本中,但它们也仍保存独立存在因此 Python 1.5.2 用户可以使用它们来安装其他模块分发版。 这里所演示的 Distutils 本身的安装脚本,是用来将该软件包安装到 Python 1.5.2 中。)</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="ch">#!/usr/bin/env python</span>
<span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;Distutils&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">description</span><span class="o">=</span><span class="s1">&#39;Python Distribution Utilities&#39;</span><span class="p">,</span>
<span class="n">author</span><span class="o">=</span><span class="s1">&#39;Greg Ward&#39;</span><span class="p">,</span>
<span class="n">author_email</span><span class="o">=</span><span class="s1">&#39;gward@python.net&#39;</span><span class="p">,</span>
<span class="n">url</span><span class="o">=</span><span class="s1">&#39;https://www.python.org/sigs/distutils-sig/&#39;</span><span class="p">,</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;distutils&#39;</span><span class="p">,</span> <span class="s1">&#39;distutils.command&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>这里与 <a class="reference internal" href="introduction.html#distutils-simple-example"><span class="std std-ref">一个简单的例子</span></a> 一节中介绍的最简版单文件分发包只有两处差异:更多的元数据,以及按包列出纯 Python 模块,而非按模块列出。 这一点很重要因为 Distutils 是由(目前)分成两个包的几十个模块组成的;显式地列出每个模块将十分繁琐并且难以维护。 有关额外元数据的更多信息,请参阅 <a class="reference internal" href="#meta-data"><span class="std std-ref">附加元数据</span></a> 一节。</p>
<p>请注意在 setup 脚本中提供的任何路径名称(文件或目录)都应当使用 Unix 约定来书写,即以斜杠分隔。 Distutils 会负责在实际使用该路径名称之前将这个与平台无关的表示形式转换为适用于你的当前平台的形式 。 这使得你的 setup 脚本可以在跨操作系统进行移植,这当然是 Distutils 的主要目标之一。 基于此精神,在本文档中的所有路径名称都是以斜杠分隔的。</p>
<p>当然,这仅适用于提供给 Distutils 函数的路径名称。 举例来说,如果你使用标准 Python 函数例如 <a class="reference internal" href="../library/glob.html#glob.glob" title="glob.glob"><code class="xref py py-func docutils literal notranslate"><span class="pre">glob.glob()</span></code></a><a class="reference internal" href="../library/os.html#os.listdir" title="os.listdir"><code class="xref py py-func docutils literal notranslate"><span class="pre">os.listdir()</span></code></a> 来指定文件,则你应当小心地编写可移植的代码而不是硬编码路径分隔符:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">glob</span><span class="o">.</span><span class="n">glob</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;mydir&#39;</span><span class="p">,</span> <span class="s1">&#39;subdir&#39;</span><span class="p">,</span> <span class="s1">&#39;*.html&#39;</span><span class="p">))</span>
<span class="n">os</span><span class="o">.</span><span class="n">listdir</span><span class="p">(</span><span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="s1">&#39;mydir&#39;</span><span class="p">,</span> <span class="s1">&#39;subdir&#39;</span><span class="p">))</span>
</pre></div>
</div>
<section id="listing-whole-packages">
<span id="listing-packages"></span><h2><span class="section-number">2.1. </span>列出全部的包<a class="headerlink" href="#listing-whole-packages" title="永久链接至标题"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">packages</span></code> 选项通知 Distutils 处理(构建、分发、安装等)在 <code class="docutils literal notranslate"><span class="pre">packages</span></code> 列表中提及的每个包中找到的所有纯 Python 模块。 当然,为做到这一点,包名称和文件系统的目录之间必须保持对应关系。 默认的对应关系是很显然的,即 <a class="reference internal" href="../library/distutils.html#module-distutils" title="distutils: Support for building and installing Python modules into an existing Python installation."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils</span></code></a> 包即相对于分发包根目录的 <code class="file docutils literal notranslate"><span class="pre">distutils</span></code> 目录。 因此,当你在你的 setup 脚本中写 <code class="docutils literal notranslate"><span class="pre">packages</span> <span class="pre">=</span> <span class="pre">['foo']</span></code> 时,你就承诺了 Distutils 将在相对于你的 setup 脚本所在目录下找到一个文件 <code class="file docutils literal notranslate"><span class="pre">foo/__init__.py</span></code> (在你的目录上可能会有不同的拼写形式,但意思已经很明白了)。 如果你违反此承诺Distutils 将发出警告但无论如何仍会处理损坏的包。</p>
<p>如果你使用不同的约定来布局你的源目录,那也没有问题:你只需提供 <code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 选项来告知 Distutils 你的约定。 例如假设你将所有For example, say you keep all Python 源代码保存在 <code class="file docutils literal notranslate"><span class="pre">lib</span></code> 下,以便“根包”中的模块(即不属于任何包的模块)位于 <code class="file docutils literal notranslate"><span class="pre">lib</span></code> 中,<code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code> 包中的模块位于 <code class="file docutils literal notranslate"><span class="pre">lib/foo</span></code> 中,依此类推。 那么你应当编写:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">package_dir</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;&#39;</span><span class="p">:</span> <span class="s1">&#39;lib&#39;</span><span class="p">}</span>
</pre></div>
</div>
<p>在你的 setup 脚本中。 这个字典的键是包名,空的包名代表根包。 字典的值是相对于你的发布包根目录的目录名。 在本例中,当你声明 <code class="docutils literal notranslate"><span class="pre">packages</span> <span class="pre">=</span> <span class="pre">['foo']</span></code> 时,你将承诺存在 <code class="file docutils literal notranslate"><span class="pre">lib/foo/__init__.py</span></code> 这个文件。</p>
<p>另一种可能的约定是将 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code> 包直接放在 <code class="file docutils literal notranslate"><span class="pre">lib</span></code> 中,将 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo.bar</span></code> 包放在 <code class="file docutils literal notranslate"><span class="pre">lib/bar</span></code> 中等等。 这可以在 setup 脚本中写为</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">package_dir</span> <span class="o">=</span> <span class="p">{</span><span class="s1">&#39;foo&#39;</span><span class="p">:</span> <span class="s1">&#39;lib&#39;</span><span class="p">}</span>
</pre></div>
</div>
<p><code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 字典中的 <code class="docutils literal notranslate"><span class="pre">package:</span> <span class="pre">dir</span></code> 条目隐式地应用于 <em>package</em> 以下的所有包,因而在这里 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo.bar</span></code> 的情况会被自动地处理。 在这个示例中,使用 <code class="docutils literal notranslate"><span class="pre">packages</span> <span class="pre">=</span> <span class="pre">['foo',</span> <span class="pre">'foo.bar']</span></code> 告知 Distutils 要查找 <code class="file docutils literal notranslate"><span class="pre">lib/__init__.py</span></code><code class="file docutils literal notranslate"><span class="pre">lib/bar/__init__.py</span></code>。 (请记住虽然 <code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 会递归地应用,但你必须在 <code class="docutils literal notranslate"><span class="pre">packages</span></code> 中显式地列出所有的包Distutils <em>不会</em> 递归地扫描你的源代码树来查找任何带有 <code class="file docutils literal notranslate"><span class="pre">__init__.py</span></code> 文件的目录。)</p>
</section>
<section id="listing-individual-modules">
<span id="listing-modules"></span><h2><span class="section-number">2.2. </span>列出单独的模块<a class="headerlink" href="#listing-individual-modules" title="永久链接至标题"></a></h2>
<p>对于一个小型的模块分发包,你可能会倾向于列出所有的模块而不是只列出包 --- 特别是在“根包”中只有一个模块(即根本不存在包)的情况下。 这种最简单的情况见 <a class="reference internal" href="introduction.html#distutils-simple-example"><span class="std std-ref">一个简单的例子</span></a> 一节;下面是一个稍微复杂一点的例子:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">py_modules</span> <span class="o">=</span> <span class="p">[</span><span class="s1">&#39;mod1&#39;</span><span class="p">,</span> <span class="s1">&#39;pkg.mod2&#39;</span><span class="p">]</span>
</pre></div>
</div>
<p>这描述了两个模块,其中一个是在 &quot;root&quot; 包中,另一个是在 <code class="xref py py-mod docutils literal notranslate"><span class="pre">pkg</span></code> 包中。 同样地,默认的包/目录布局表明这两个模块位于 <code class="file docutils literal notranslate"><span class="pre">mod1.py</span></code><code class="file docutils literal notranslate"><span class="pre">pkg/mod2.py</span></code> 中,并且也存在 <code class="file docutils literal notranslate"><span class="pre">pkg/__init__.py</span></code>。 同样地,你可以使用 <code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 选项来重载包/目录的对应关系。</p>
</section>
<section id="describing-extension-modules">
<span id="describing-extensions"></span><h2><span class="section-number">2.3. </span>描述扩展模块<a class="headerlink" href="#describing-extension-modules" title="永久链接至标题"></a></h2>
<p>正如编写Python扩展模块比编写纯Python模块要复杂一些一样在Distutils中描述它们也要复杂一些。与纯模块不同仅仅列出模块或包并期望Distutils出去找到正确的文件是不够的您必须指定扩展名、源文件和任何编译/链接要求(包括要链接的目录、库等)。</p>
<p>所有这些都是通过 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 的另一个关键字参数 <code class="docutils literal notranslate"><span class="pre">ext_modules</span></code> 选项实现的。 <code class="docutils literal notranslate"><span class="pre">ext_modules</span></code> 是 由 <a class="reference internal" href="apiref.html#distutils.core.Extension" title="distutils.core.Extension"><code class="xref py py-class docutils literal notranslate"><span class="pre">Extension</span></code></a> 实例组成的列表,每个实例描述一个扩展模块。 假设你的发行版包括一个扩展模块,名为 <code class="xref py py-mod docutils literal notranslate"><span class="pre">foo</span></code> 并由 <code class="file docutils literal notranslate"><span class="pre">foo.c</span></code> 实现。 如果不需要编译器/链接器的额外指令,描述这个扩展很简单:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.c&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p><code class="xref py py-class docutils literal notranslate"><span class="pre">Extension</span></code> 类可以与 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 一起从 <a class="reference internal" href="apiref.html#module-distutils.core" title="distutils.core: The core Distutils functionality"><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.core</span></code></a> 导入。 因此,只包含这一个扩展而不包含其他扩展的模块分发版的安装脚本可能是:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.core</span> <span class="kn">import</span> <span class="n">setup</span><span class="p">,</span> <span class="n">Extension</span>
<span class="n">setup</span><span class="p">(</span><span class="n">name</span><span class="o">=</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span>
<span class="n">version</span><span class="o">=</span><span class="s1">&#39;1.0&#39;</span><span class="p">,</span>
<span class="n">ext_modules</span><span class="o">=</span><span class="p">[</span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.c&#39;</span><span class="p">])],</span>
<span class="p">)</span>
</pre></div>
</div>
<p><code class="xref py py-class docutils literal notranslate"><span class="pre">Extension</span></code> 类(实际上,由 <strong class="command">build_ext</strong> 命令实现的底层扩展构建机制)在描述 Python 扩展时支持很大的灵活性,这将在以下部分中进行解释。</p>
<section id="extension-names-and-packages">
<h3><span class="section-number">2.3.1. </span>扩展名和软件包<a class="headerlink" href="#extension-names-and-packages" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="apiref.html#distutils.core.Extension" title="distutils.core.Extension"><code class="xref py py-class docutils literal notranslate"><span class="pre">Extension</span></code></a> 构造器的第一个参数始终是扩展的名称,包括任何包名称。 例如,:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;src/foo1.c&#39;</span><span class="p">,</span> <span class="s1">&#39;src/foo2.c&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>描述了根包中的一个扩展,而::</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;pkg.foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;src/foo1.c&#39;</span><span class="p">,</span> <span class="s1">&#39;src/foo2.c&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>描述了 <code class="xref py py-mod docutils literal notranslate"><span class="pre">pkg</span></code> 包中的相同扩展。 在这两种情况下,源文件和生成的目标代码是相同的;唯一的区别是所产生的扩展处在文件系统中的何处(相应地在 Python 的命名空间层级结构中处在何处)。</p>
<p>如果在同一个包中(或在同一基本包下)有多个扩展,请使用 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 的关键字参数 <code class="docutils literal notranslate"><span class="pre">ext_package</span></code>。 例如,:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">ext_package</span><span class="o">=</span><span class="s1">&#39;pkg&#39;</span><span class="p">,</span>
<span class="n">ext_modules</span><span class="o">=</span><span class="p">[</span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.c&#39;</span><span class="p">]),</span>
<span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;subpkg.bar&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;bar.c&#39;</span><span class="p">])],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>将把 <code class="file docutils literal notranslate"><span class="pre">foo.c</span></code> 编译为扩展 <code class="xref py py-mod docutils literal notranslate"><span class="pre">pkg.foo</span></code>,把 <code class="file docutils literal notranslate"><span class="pre">bar.c</span></code> 编译为 <code class="xref py py-mod docutils literal notranslate"><span class="pre">pkg.subpkg.bar</span></code></p>
</section>
<section id="extension-source-files">
<h3><span class="section-number">2.3.2. </span>扩展的源文件<a class="headerlink" href="#extension-source-files" title="永久链接至标题"></a></h3>
<p><a class="reference internal" href="apiref.html#distutils.core.Extension" title="distutils.core.Extension"><code class="xref py py-class docutils literal notranslate"><span class="pre">Extension</span></code></a> 构造器的第二个参数是源文件列表。 由于 Distutils 目前只支持 C、C++ 和 Objective-C 扩展,因此这些扩展通常是 C/C++/Objective-C 源文件。 (请确保使用适当的扩展名来区分 C++ 源文件: <code class="file docutils literal notranslate"><span class="pre">.cc</span></code><code class="file docutils literal notranslate"><span class="pre">.cpp</span></code> 看来能够同时被 Unix 和 Windows 编译器所识别。)</p>
<p>但是,您也可以在列表中包括 SWIG 接口 (<code class="file docutils literal notranslate"><span class="pre">.i</span></code>) 文件;<strong class="command">build_ext</strong> 命令知道如何处理 SWIG 扩展:它将在接口文件上运行 SWIG并将生成的 C/C++ 文件编译为你的扩展。</p>
<p>尽管有此警告SWIG的选项目前可以这样传递</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">ext_modules</span><span class="o">=</span><span class="p">[</span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;_foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.i&#39;</span><span class="p">],</span>
<span class="n">swig_opts</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;-modern&#39;</span><span class="p">,</span> <span class="s1">&#39;-I../include&#39;</span><span class="p">])],</span>
<span class="n">py_modules</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;foo&#39;</span><span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>或者在命令行上,像这样</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&gt;</span> <span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">build_ext</span> <span class="o">--</span><span class="n">swig</span><span class="o">-</span><span class="n">opts</span><span class="o">=</span><span class="s2">&quot;-modern -I../include&quot;</span>
</pre></div>
</div>
<p>在某些平台上可以包含由编译器处理并包含在扩展中的非源文件。目前这只是指Visual C++的Windows消息文本<code class="file docutils literal notranslate"><span class="pre">.mc</span></code>)文件和资源定义(<code class="file docutils literal notranslate"><span class="pre">.rc</span></code>)。这些文件将被编译为二进制资源(<code class="file docutils literal notranslate"><span class="pre">.res</span></code>)文件,并链接到可执行文件中。</p>
</section>
<section id="preprocessor-options">
<h3><span class="section-number">2.3.3. </span>预处理器选项<a class="headerlink" href="#preprocessor-options" title="永久链接至标题"></a></h3>
<p>如果你需要指定要搜索的include目录或预处理器宏来define/undefine那么<code class="xref py py-class docutils literal notranslate"><span class="pre">Extension`的三个可选参数将有所帮助:``include_dirs`</span></code><code class="docutils literal notranslate"><span class="pre">define_macros``和``undef_macros</span></code></p>
<p>例如,如果你的扩展需要分发根目录下的 <code class="file docutils literal notranslate"><span class="pre">include</span></code> 目录中的头文件,请使用 <code class="docutils literal notranslate"><span class="pre">include_dirs</span></code> 选项:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.c&#39;</span><span class="p">],</span> <span class="n">include_dirs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;include&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>你可以在那里指定绝对目录;如果你知道你的扩展只能在安装到 <code class="file docutils literal notranslate"><span class="pre">/usr</span></code> 的 X11R6 的 Unix 系统上构建,那么你就可以:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="s1">&#39;foo&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;foo.c&#39;</span><span class="p">],</span> <span class="n">include_dirs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;/usr/include/X11&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>如果你计划分发代码应该避免这种不可移植的用法最好像这样编写C代码</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#include &lt;X11/Xlib.h&gt;</span>
</pre></div>
</div>
<p>如果你需要包含来自其它 Python 扩展的头文件,你可以利用这样一个事实,即 Distutils <strong class="command">install_headers</strong> 命令以一致的方式安装头文件。 例如Numerical Python 头文件 (在标准 Unix 安装版上) 会安装到 <code class="file docutils literal notranslate"><span class="pre">/usr/local/include/python1.5/Numerical</span></code> (具体位置将根据你的平台和 Python 安装版而有所不同)。 由于在构建Python 扩展时Python include 目录 --- 在本例中为 <code class="file docutils literal notranslate"><span class="pre">/usr/local/include/python1.5</span></code> --- 总是会包含在搜索路径中,因此最好的做法是像这样编写 C 代码:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#include &lt;Numerical/arrayobject.h&gt;</span>
</pre></div>
</div>
<p>但是,如果必须将 <code class="file docutils literal notranslate"><span class="pre">Numerical</span></code> include 目录放在头文件搜索路径中,则可以使用 Distutils <a class="reference internal" href="apiref.html#module-distutils.sysconfig" title="distutils.sysconfig: Low-level access to configuration information of the Python interpreter."><code class="xref py py-mod docutils literal notranslate"><span class="pre">distutils.sysconfig</span></code></a> 模块找到该目录:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">distutils.sysconfig</span> <span class="kn">import</span> <span class="n">get_python_inc</span>
<span class="n">incdir</span> <span class="o">=</span> <span class="n">os</span><span class="o">.</span><span class="n">path</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">get_python_inc</span><span class="p">(</span><span class="n">plat_specific</span><span class="o">=</span><span class="mi">1</span><span class="p">),</span> <span class="s1">&#39;Numerical&#39;</span><span class="p">)</span>
<span class="n">setup</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">Extension</span><span class="p">(</span><span class="o">...</span><span class="p">,</span> <span class="n">include_dirs</span><span class="o">=</span><span class="p">[</span><span class="n">incdir</span><span class="p">]),</span>
<span class="p">)</span>
</pre></div>
</div>
<p>尽管这是非常可移植的——无论平台如何它都可以在任何Python安装中工作——但以合理的方式编写C代码可能更容易。</p>
<p>您可以使用``define_macros``和``undef_macros``选项 define 和 undefine 预处理器宏。<code class="docutils literal notranslate"><span class="pre">define_macros``采用一个``(name,</span> <span class="pre">value)``元组列表,其中``name``是要定义的宏的名称(字符串),``value``是其值:字符串或“``None</span></code>。(将宏``FOO``定义为``None``相当于C源代码中的空``#define FOO``:对于大多数编译器,这会将``FOO``设置为字符串``1``。)``undef_macros``只是一个undefine的宏列表。</p>
<p>例如:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">define_macros</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;NDEBUG&#39;</span><span class="p">,</span> <span class="s1">&#39;1&#39;</span><span class="p">),</span>
<span class="p">(</span><span class="s1">&#39;HAVE_STRFTIME&#39;</span><span class="p">,</span> <span class="kc">None</span><span class="p">)],</span>
<span class="n">undef_macros</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;HAVE_FOO&#39;</span><span class="p">,</span> <span class="s1">&#39;HAVE_BAR&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>相当于将其放在每个C源文件的顶部</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="c1">#define NDEBUG 1</span>
<span class="c1">#define HAVE_STRFTIME</span>
<span class="c1">#undef HAVE_FOO</span>
<span class="c1">#undef HAVE_BAR</span>
</pre></div>
</div>
</section>
<section id="library-options">
<h3><span class="section-number">2.3.4. </span>库选项<a class="headerlink" href="#library-options" title="永久链接至标题"></a></h3>
<p>你还可以指定在构建扩展时要链接的库,以及搜索这些库的目录。 <code class="docutils literal notranslate"><span class="pre">libraries</span></code> 选项是要链接的库列表,<code class="docutils literal notranslate"><span class="pre">library_dirs</span></code> 是要在链接时搜索库的目录列表,<code class="docutils literal notranslate"><span class="pre">runtime_library_dirs</span></code> 是要在运行时搜索共享(动态加载)库的目录的列表。</p>
<p>例如,如果你需要链接到目标系统上标准库搜索路径中已知的库</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">libraries</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;gdbm&#39;</span><span class="p">,</span> <span class="s1">&#39;readline&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>如果你需要链接到非标准位置的库,则必须将该位置包含在 <code class="docutils literal notranslate"><span class="pre">library_dirs</span></code> 中:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">Extension</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">library_dirs</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;/usr/X11R6/lib&#39;</span><span class="p">],</span>
<span class="n">libraries</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;X11&#39;</span><span class="p">,</span> <span class="s1">&#39;Xt&#39;</span><span class="p">])</span>
</pre></div>
</div>
<p>(同样,如果你打算分发代码,应该避免这种不可移植的构造。)</p>
</section>
<section id="other-options">
<h3><span class="section-number">2.3.5. </span>其它选项<a class="headerlink" href="#other-options" title="永久链接至标题"></a></h3>
<p>还有一些其它选项可以用于处理特殊情况。</p>
<p><code class="docutils literal notranslate"><span class="pre">optional</span></code> 选项是一个布尔值;如果它为真值,则扩展中的生成失败不会中止生成过程,而是简单地不安装失败的扩展。</p>
<p><code class="docutils literal notranslate"><span class="pre">extra_objects</span></code> 选项是要传递给链接器的对象文件列表。 这些文件不能有扩展名,因为使用的是编译器的默认扩展名。</p>
<p><code class="docutils literal notranslate"><span class="pre">extra_compile_args</span></code><code class="docutils literal notranslate"><span class="pre">extra_link_args</span></code> 可用于为相应的编译器和链接器命令行指定额外的命令行选项。</p>
<p><code class="docutils literal notranslate"><span class="pre">export_symbols</span></code> 仅在 Windows 上适用。 它可以包含要导出的符号(函数或变量)列表。 生成编译的扩展时不需要此选项Distutils 会自动将 <code class="docutils literal notranslate"><span class="pre">initmodule</span></code> 添加到导出的符号列表中。</p>
<p><code class="docutils literal notranslate"><span class="pre">depends</span></code> 选项是扩展所依赖的文件列表(例如头文件)。 build 命令将调用源上的编译器以重新生成扩展(如果自上一次生成以来此文件上的任何扩展已被修改)。</p>
</section>
</section>
<section id="relationships-between-distributions-and-packages">
<h2><span class="section-number">2.4. </span>分发和软件包之间的关系<a class="headerlink" href="#relationships-between-distributions-and-packages" title="永久链接至标题"></a></h2>
<p>一个分发可能以三种特定方式与软件包相关:</p>
<ol class="arabic simple">
<li><p>它可能需要软件包或模块。</p></li>
<li><p>它可能提供软件包或模块。</p></li>
<li><p>它可能废弃软件包或模块。</p></li>
</ol>
<p>可以使用 <a class="reference internal" href="apiref.html#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-func docutils literal notranslate"><span class="pre">distutils.core.setup()</span></code></a> 函数的关键字参数来指定这些关系。</p>
<p>可以通过将 <em>requires</em> 关键字参数提供给 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 来指定对其他 Python 模块和包的依赖关系。 其值必须是字符串列表。 每个字符串都指定了所需的软件包,并可以选择哪些版本满足要求。</p>
<p>要指定需要模块或软件包的任何版本,字符串应该完全由模块或软件包的名称组成。 示例包括 <code class="docutils literal notranslate"><span class="pre">'mymodule'</span></code><code class="docutils literal notranslate"><span class="pre">'xml.parsers.expat'</span></code></p>
<p>如果需要特定的版本,可以在括号中提供一系列限定符。每个限定符可以由一个比较运算符和一个版本号组成。可接受的比较运算符为:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="o">&lt;</span> <span class="o">&gt;</span> <span class="o">==</span>
<span class="o">&lt;=</span> <span class="o">&gt;=</span> <span class="o">!=</span>
</pre></div>
</div>
<p>这些可以通过使用逗号分隔的多个限定符以及可选的空格进行组合。在这种情况下所有限定符都必须匹配使用逻辑AND来组合评估。</p>
<p>让我们看一堆例子:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 35%" />
<col style="width: 65%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Requires 表达式</p></th>
<th class="head"><p>说明</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">==1.0</span></code></p></td>
<td><p>只有``1.0``版本兼容</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">&gt;1.0,</span> <span class="pre">!=1.5.1,</span> <span class="pre">&lt;2.0</span></code></p></td>
<td><p><code class="docutils literal notranslate"><span class="pre">1.0</span></code> 之后和 <code class="docutils literal notranslate"><span class="pre">2.0</span></code> 之前的任何版本都是兼容的,<code class="docutils literal notranslate"><span class="pre">1.5.1</span></code> 除外</p></td>
</tr>
</tbody>
</table>
<p>既然我们可以指定依赖项,我们还需要能够指定我们提供的其它发行版可能需要的内容。这是通过将 <em>provides</em> 关键字参数用于 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 来完成的。 该关键字的值是一个字符串列表每个字符串都命名一个Python模块或软件包并可选择标识版本。 如果未指定版本,则假定与该发行版的版本相匹配。</p>
<p>一些例子:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 31%" />
<col style="width: 69%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>Provides 表达式</p></th>
<th class="head"><p>说明</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">mypkg</span></code></p></td>
<td><p>Provide <code class="docutils literal notranslate"><span class="pre">mypkg</span></code>, 使用该分发版的版本</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">mypkg</span> <span class="pre">(1.1)</span></code></p></td>
<td><p>提供版本为 1.1的``mypkg``,不管分发版的版本</p></td>
</tr>
</tbody>
</table>
<p>一个软件包可以使用 <em>obsoletes</em> 关键字参数声明它已经废弃了其它软件包。它的值类似于 <em>requires</em> 关键字的值:一个给出模块或软件包说明符的字符串列表。每个说明符由一个模块或软件包名称组成,后面可选地跟有一个或多个版本限定符。版本限定符在模块或软件包名称后面的括号中给出。</p>
<p>限定符标识的版本是那些被所描述的分发版本废弃的版本。如果没有给出限定符,那么指定的模块或软件包的所有版本都被认为是废弃的。</p>
</section>
<section id="installing-scripts">
<span id="distutils-installing-scripts"></span><h2><span class="section-number">2.5. </span>安装脚本<a class="headerlink" href="#installing-scripts" title="永久链接至标题"></a></h2>
<p>到目前为止我们一直在处理纯Python模块和非纯Python模块它们通常不是自己运行的而是通过脚本导入的。</p>
<p>脚本是包含Python源代码的文件旨在从命令行启动。脚本不需要Distutils来做任何非常复杂的事情。唯一聪明的功能是如果脚本的第一行以``#!``开头并且包含单词“python”Distutils将调整第一行以引用当前解释器位置。默认情况下它被替换为当前解释器位置。选项:option:<cite>!--executable`(或:option:</cite>!-e`)将允许显式覆盖解释器路径。</p>
<p><code class="docutils literal notranslate"><span class="pre">scripts</span></code> 选项只是要以这种方式处理的文件列表。 从 PyXML 安装脚本</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">scripts</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;scripts/xmlproc_parse&#39;</span><span class="p">,</span> <span class="s1">&#39;scripts/xmlproc_val&#39;</span><span class="p">]</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.1 版更改: </span>如果没有提供模板,所有脚本也将被添加到 <code class="docutils literal notranslate"><span class="pre">MANIFEST</span></code> 文件中。请参见 <a class="reference internal" href="sourcedist.html#manifest"><span class="std std-ref">指定要分发的文件</span></a></p>
</div>
</section>
<section id="installing-package-data">
<span id="distutils-installing-package-data"></span><h2><span class="section-number">2.6. </span>安装软件包数据<a class="headerlink" href="#installing-package-data" title="永久链接至标题"></a></h2>
<p>通常,需要将额外的文件安装到软件包中。这些文件通常是与软件包的实现密切相关的数据,或者是包含使用软件包的程序员可能感兴趣的文档的文本文件。这些文件被称为 <em class="dfn">package data</em></p>
<p>可以使用 <code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 函数的关键字参数 <code class="docutils literal notranslate"><span class="pre">package_data</span></code> 将软件包数据添加到软件包中。 该值必须是从软件包名到应该复制到软件包中的相对路径名列表的映射。 路径被解释为相对于包含软件包的目录(如果合适,将使用来自 <code class="docutils literal notranslate"><span class="pre">package_dir</span></code> 映射的信息);也就是说,这些文件应该是软件包源目录中的一部分。 它们也可能包含 glob 模式。</p>
<p>路径名称可以包含目录部分;任何必要的目录都将在安装过程中创建。</p>
<p>例如,如果一个软件包应该包含一个有多个数据文件的子目录,那么这些文件可以在源树中按如下方式排列</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="o">.</span><span class="n">py</span>
<span class="n">src</span><span class="o">/</span>
<span class="n">mypkg</span><span class="o">/</span>
<span class="fm">__init__</span><span class="o">.</span><span class="n">py</span>
<span class="n">module</span><span class="o">.</span><span class="n">py</span>
<span class="n">data</span><span class="o">/</span>
<span class="n">tables</span><span class="o">.</span><span class="n">dat</span>
<span class="n">spoons</span><span class="o">.</span><span class="n">dat</span>
<span class="n">forks</span><span class="o">.</span><span class="n">dat</span>
</pre></div>
</div>
<p><code class="xref py py-func docutils literal notranslate"><span class="pre">setup()</span></code> 的相应调用可能是</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">packages</span><span class="o">=</span><span class="p">[</span><span class="s1">&#39;mypkg&#39;</span><span class="p">],</span>
<span class="n">package_dir</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;mypkg&#39;</span><span class="p">:</span> <span class="s1">&#39;src/mypkg&#39;</span><span class="p">},</span>
<span class="n">package_data</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;mypkg&#39;</span><span class="p">:</span> <span class="p">[</span><span class="s1">&#39;data/*.dat&#39;</span><span class="p">]},</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.1 版更改: </span>如果没有提供模板,则所有与 <code class="docutils literal notranslate"><span class="pre">package_data</span></code> 匹配的文件都将添加到 <code class="docutils literal notranslate"><span class="pre">MANIFEST</span></code> 文件中。 请参见 <a class="reference internal" href="sourcedist.html#manifest"><span class="std std-ref">指定要分发的文件</span></a></p>
</div>
</section>
<section id="installing-additional-files">
<span id="distutils-additional-files"></span><h2><span class="section-number">2.7. </span>安装其它文件<a class="headerlink" href="#installing-additional-files" title="永久链接至标题"></a></h2>
<p><code class="docutils literal notranslate"><span class="pre">data_files</span></code> 选项可用于指定模块分发所需的其它文件:配置文件、消息目录、数据文件,以及任何不属于前述类别的文件。</p>
<p><code class="docutils literal notranslate"><span class="pre">data_files</span></code> 以如下方式指定 (<em>directory</em>, <em>files</em>) 对的序列:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">data_files</span><span class="o">=</span><span class="p">[(</span><span class="s1">&#39;bitmaps&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;bm/b1.gif&#39;</span><span class="p">,</span> <span class="s1">&#39;bm/b2.gif&#39;</span><span class="p">]),</span>
<span class="p">(</span><span class="s1">&#39;config&#39;</span><span class="p">,</span> <span class="p">[</span><span class="s1">&#39;cfg/data.cfg&#39;</span><span class="p">])],</span>
<span class="p">)</span>
</pre></div>
</div>
<p>序列中的每队(<em>directory</em><em>files</em>)指定安装目录和要在其中安装的文件。</p>
<p><em>files</em> 中的每个文件名都是相对于软件包源发行版顶部的 <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 脚本进行解释的。 请注意,您可以指定安装数据文件的目录,但不能重命名数据文件本身。</p>
<p><em>directory</em> 应该是一个相对路径。它是相对于安装前缀来解释的Python 的 <code class="docutils literal notranslate"><span class="pre">sys.prefix</span></code> 用于系统安装;<code class="docutils literal notranslate"><span class="pre">site.USER_BASE</span></code> 用于用户安装)。 Distutils 允许将 <em>directory</em> 作为一个绝对的安装路径,但这是不鼓励的,因为它与 wheel 封装格式不兼容。不使用来自 <em>files</em> 的目录信息来确定已安装文件的最终位置;只使用文件的名称。</p>
<p>你可以将 <code class="docutils literal notranslate"><span class="pre">data_files</span></code> 选项指定为一个简单的文件序列,而无需指定目标目录,但不建议这样做,在这种情况下,<strong class="command">install</strong> 命令将打印警告。 要将数据文件直接安装到目标目录中,应提供一个空字符串作为目录。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.1 版更改: </span>如果没有提供模板,则所有与 <code class="docutils literal notranslate"><span class="pre">data_files</span></code> 匹配的文件都将添加到 <code class="docutils literal notranslate"><span class="pre">MANIFEST</span></code> 文件中。 请参见 <a class="reference internal" href="sourcedist.html#manifest"><span class="std std-ref">指定要分发的文件</span></a></p>
</div>
</section>
<section id="additional-meta-data">
<span id="meta-data"></span><h2><span class="section-number">2.8. </span>附加元数据<a class="headerlink" href="#additional-meta-data" title="永久链接至标题"></a></h2>
<p>安装脚本可以包括除了名称和版本之外的附加元数据。这些信息包括:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 30%" />
<col style="width: 36%" />
<col style="width: 23%" />
<col style="width: 11%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>元数据</p></th>
<th class="head"><p>描述</p></th>
<th class="head"><p></p></th>
<th class="head"><p>备注</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">name</span></code></p></td>
<td><p>包名称</p></td>
<td><p>短字符串</p></td>
<td><p>(1)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">version</span></code></p></td>
<td><p>此发布的版本</p></td>
<td><p>短字符串</p></td>
<td><p>(1)(2)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">author</span></code></p></td>
<td><p>软件包作者的姓名</p></td>
<td><p>短字符串</p></td>
<td><p>(3)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">author_email</span></code></p></td>
<td><p>软件包的作者的电子邮件地址</p></td>
<td><p>电子邮件地址</p></td>
<td><p>(3)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">maintainer</span></code></p></td>
<td><p>软件包维护者的名字</p></td>
<td><p>短字符串</p></td>
<td><p>(3)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">maintainer_email</span></code></p></td>
<td><p>软件包维护者的电子邮件地址</p></td>
<td><p>电子邮件地址</p></td>
<td><p>(3)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">url</span></code></p></td>
<td><p>软件包的网址</p></td>
<td><p>网址</p></td>
<td><p>(1)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">description</span></code></p></td>
<td><p>软件包的简短摘要说明</p></td>
<td><p>短字符串</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">long_description</span></code></p></td>
<td><p>软件包的详细说明</p></td>
<td><p>长字符串</p></td>
<td><p>(4)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">download_url</span></code></p></td>
<td><p>可以下载软件包的网址</p></td>
<td><p>网址</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">classifiers</span></code></p></td>
<td><p>分类列表</p></td>
<td><p>字符串列表</p></td>
<td><p>(6)(7)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">platforms</span></code></p></td>
<td><p>平台清单</p></td>
<td><p>字符串列表</p></td>
<td><p>(6)(8)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">keywords</span></code></p></td>
<td><p>关键字列表</p></td>
<td><p>字符串列表</p></td>
<td><p>(6)(8)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">license</span></code></p></td>
<td><p>软件包许可证</p></td>
<td><p>短字符串</p></td>
<td><p>(5)</p></td>
</tr>
</tbody>
</table>
<p>注释:</p>
<ol class="arabic simple">
<li><p>这些字段是必需的。</p></li>
<li><p>建议版本采用 <em>major.minor[.patch[.sub]]</em> 的形式。</p></li>
<li><p>必须确定作者或维护者。如果提供了维护者distutils 会在 <code class="file docutils literal notranslate"><span class="pre">PKG-INFO</span></code> 中将其列为作者。</p></li>
<li><p>PyPI在发布软件包时使用``long_description``字段来构建其项目页面。</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">license</span></code> 字段是一个文本,指示软件包中的许可证,其中该许可证不是从 “license” Trove分类器中选择的。请参见 <code class="docutils literal notranslate"><span class="pre">Classifier</span></code> 字段。 请注意,有一个 <code class="docutils literal notranslate"><span class="pre">licence</span></code> 分发选项,该选项已被弃用,但仍充当 <code class="docutils literal notranslate"><span class="pre">license</span></code> 字段的别名。</p></li>
<li><p>此字段必须是一个列表。</p></li>
<li><p>有效的分类器在 <a class="reference external" href="https://pypi.org/classifiers">PyPI</a> 上列出。</p></li>
<li><p>为了保持向后兼容性,此字段还接受一个字符串。如果传递逗号分隔的字符串``'foo, bar'<code class="docutils literal notranslate"><span class="pre">,它将被转换为``['foo',</span> <span class="pre">'bar']</span></code>,否则,它将转换为一个字符串列表。</p></li>
</ol>
<dl class="simple">
<dt>'短字符串'</dt><dd><p>一行文字不超过200个字符。</p>
</dd>
<dt>'长字符串'</dt><dd><p>Multiple lines of plain text in reStructuredText format (see
<a class="reference external" href="http://docutils.sourceforge.net/">http://docutils.sourceforge.net/</a>).</p>
</dd>
<dt>'字符串列表'</dt><dd><p>请参见下文。</p>
</dd>
</dl>
<p>对版本信息进行编码本身就是一门艺术。Python包通常遵循版本格式 <em>major.minor[.patch][sub]</em> 。初始的、实验性的软件版本的主数字是0。对于表示包中主要里程碑的版本主版本会递增。当重要的新特性添加到包中时次版本编号会增加。当发布错误修复程序时补丁编号会增加。附加的尾随版本信息有时用于指示子版本。这些是“a1a2aN”对于alpha版本功能和API可能会更改“b1b2bN”针对beta版本它只修复了错误和“pr1pr2……prN”用于最终的预发布测试。一些例子</p>
<dl class="simple">
<dt>0.1.0</dt><dd><p>一个软件包的第一个实验性发布</p>
</dd>
<dt>1.0.1a2</dt><dd><p>1.0的第一个补丁版本的第二个alpha版本</p>
</dd>
</dl>
<p><code class="docutils literal notranslate"><span class="pre">classifiers</span></code> 必须在列表中指定</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">setup</span><span class="p">(</span><span class="o">...</span><span class="p">,</span>
<span class="n">classifiers</span><span class="o">=</span><span class="p">[</span>
<span class="s1">&#39;Development Status :: 4 - Beta&#39;</span><span class="p">,</span>
<span class="s1">&#39;Environment :: Console&#39;</span><span class="p">,</span>
<span class="s1">&#39;Environment :: Web Environment&#39;</span><span class="p">,</span>
<span class="s1">&#39;Intended Audience :: End Users/Desktop&#39;</span><span class="p">,</span>
<span class="s1">&#39;Intended Audience :: Developers&#39;</span><span class="p">,</span>
<span class="s1">&#39;Intended Audience :: System Administrators&#39;</span><span class="p">,</span>
<span class="s1">&#39;License :: OSI Approved :: Python Software Foundation License&#39;</span><span class="p">,</span>
<span class="s1">&#39;Operating System :: MacOS :: MacOS X&#39;</span><span class="p">,</span>
<span class="s1">&#39;Operating System :: Microsoft :: Windows&#39;</span><span class="p">,</span>
<span class="s1">&#39;Operating System :: POSIX&#39;</span><span class="p">,</span>
<span class="s1">&#39;Programming Language :: Python&#39;</span><span class="p">,</span>
<span class="s1">&#39;Topic :: Communications :: Email&#39;</span><span class="p">,</span>
<span class="s1">&#39;Topic :: Office/Business&#39;</span><span class="p">,</span>
<span class="s1">&#39;Topic :: Software Development :: Bug Tracking&#39;</span><span class="p">,</span>
<span class="p">],</span>
<span class="p">)</span>
</pre></div>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版更改: </span>现在 <a class="reference internal" href="apiref.html#distutils.core.setup" title="distutils.core.setup"><code class="xref py py-class docutils literal notranslate"><span class="pre">setup</span></code></a><code class="docutils literal notranslate"><span class="pre">classifiers</span></code><code class="docutils literal notranslate"><span class="pre">keywords</span></code><code class="docutils literal notranslate"><span class="pre">platforms</span></code> 字段未指定为列表或字符串时发出警告。</p>
</div>
</section>
<section id="debugging-the-setup-script">
<span id="debug-setup-script"></span><h2><span class="section-number">2.9. </span>调试安装脚本<a class="headerlink" href="#debugging-the-setup-script" title="永久链接至标题"></a></h2>
<p>有时会出现问题,并且安装脚本不能执行开发人员想要的操作。</p>
<p>Distutils在运行安装脚本时捕获任何异常并在脚本终止前打印一条简单的错误消息。这种行为的动机是为了不让那些对Python不太了解并试图安装软件包的管理员感到困惑。如果他们从Distutils的内部深处得到了一个很长的追溯他们可能会认为这个软件包或Python安装坏了因为他们没有一直读到底部看到这是一个权限问题。</p>
<p>另一方面,这并不能帮助开发人员找到失败的原因。 为此,<span class="target" id="index-2"></span><code class="xref std std-envvar docutils literal notranslate"><span class="pre">DISTUTILS_DEBUG</span></code> 环境变量可以设置为除空字符串之外的任何值distutils 现在将打印有关其正在执行的操作的详细信息,在发生异常时转储完整的回溯,并在外部程序(如 C 编译器)失败时打印整个命令行。</p>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">2. 编写安装脚本</a><ul>
<li><a class="reference internal" href="#listing-whole-packages">2.1. 列出全部的包</a></li>
<li><a class="reference internal" href="#listing-individual-modules">2.2. 列出单独的模块</a></li>
<li><a class="reference internal" href="#describing-extension-modules">2.3. 描述扩展模块</a><ul>
<li><a class="reference internal" href="#extension-names-and-packages">2.3.1. 扩展名和软件包</a></li>
<li><a class="reference internal" href="#extension-source-files">2.3.2. 扩展的源文件</a></li>
<li><a class="reference internal" href="#preprocessor-options">2.3.3. 预处理器选项</a></li>
<li><a class="reference internal" href="#library-options">2.3.4. 库选项</a></li>
<li><a class="reference internal" href="#other-options">2.3.5. 其它选项</a></li>
</ul>
</li>
<li><a class="reference internal" href="#relationships-between-distributions-and-packages">2.4. 分发和软件包之间的关系</a></li>
<li><a class="reference internal" href="#installing-scripts">2.5. 安装脚本</a></li>
<li><a class="reference internal" href="#installing-package-data">2.6. 安装软件包数据</a></li>
<li><a class="reference internal" href="#installing-additional-files">2.7. 安装其它文件</a></li>
<li><a class="reference internal" href="#additional-meta-data">2.8. 附加元数据</a></li>
<li><a class="reference internal" href="#debugging-the-setup-script">2.9. 调试安装脚本</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="introduction.html"
title="上一章"><span class="section-number">1. </span>Distutils 模块介绍</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="configfile.html"
title="下一章"><span class="section-number">3. </span>编写设置脚本的配置文件</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/setupscript.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="configfile.html" title="3. 编写设置脚本的配置文件"
>下一页</a> |</li>
<li class="right" >
<a href="introduction.html" title="1. Distutils 模块介绍"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,407 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>4. 创建源代码分发包 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="next" title="5. 创建构建分发版" href="builtdist.html" />
<link rel="prev" title="3. 编写设置脚本的配置文件" href="configfile.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/sourcedist.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">4. 创建源代码分发包</a><ul>
<li><a class="reference internal" href="#specifying-the-files-to-distribute">4.1. 指定要分发的文件</a></li>
<li><a class="reference internal" href="#manifest-related-options">4.2. 声明相关选项</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="configfile.html"
title="上一章"><span class="section-number">3. </span>编写设置脚本的配置文件</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="builtdist.html"
title="下一章"><span class="section-number">5. </span>创建构建分发版</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/sourcedist.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/sourcedist.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="builtdist.html" title="5. 创建构建分发版"
accesskey="N">下一页</a> |</li>
<li class="right" >
<a href="configfile.html" title="3. 编写设置脚本的配置文件"
accesskey="P">上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" accesskey="U">分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="creating-a-source-distribution">
<span id="source-dist"></span><h1><span class="section-number">4. </span>创建源代码分发包<a class="headerlink" href="#creating-a-source-distribution" title="永久链接至标题"></a></h1>
<div class="admonition note">
<p class="admonition-title">注解</p>
<p>这篇文档是历史遗留文档,在 <a class="reference external" href="https://setuptools.readthedocs.io/en/latest/setuptools.html">https://setuptools.readthedocs.io/en/latest/setuptools.html</a> 上的 <code class="docutils literal notranslate"><span class="pre">setuptools</span></code> 文档独立涵盖此处包含的所有相关信息之后,将不再单独作为正式文档保留。</p>
</div>
<p><a class="reference internal" href="introduction.html#distutils-simple-example"><span class="std std-ref">一个简单的例子</span></a> 一节所示,可以使用 <strong class="command">sdist</strong> 命令来创建一个源代码分发包。 在最简单的场景下,:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">sdist</span>
</pre></div>
</div>
<p>(假定你没有在设置脚本或配置文件中指定任何 <strong class="command">sdist</strong> 选项),<strong class="command">sdist</strong> 将创建基于当前平台的默认格式的归档。 在 Unix 上默认格式为 gzip 的 tar 文件,而在 Windows 上则为 ZIP 文件。</p>
<p>你可以使用 <code class="xref std std-option docutils literal notranslate"><span class="pre">--formats</span></code> 选项来指定任何你想要的格式,例如:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">sdist</span> <span class="o">--</span><span class="n">formats</span><span class="o">=</span><span class="n">gztar</span><span class="p">,</span><span class="nb">zip</span>
</pre></div>
</div>
<p>是创建一个 gzip 的 tar 文件和一个 zip 文件。 可用的格式有:</p>
<table class="docutils align-default">
<colgroup>
<col style="width: 24%" />
<col style="width: 56%" />
<col style="width: 20%" />
</colgroup>
<thead>
<tr class="row-odd"><th class="head"><p>格式</p></th>
<th class="head"><p>描述</p></th>
<th class="head"><p>备注</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">zip</span></code></p></td>
<td><p>zip 文件 (<code class="file docutils literal notranslate"><span class="pre">.zip</span></code>)</p></td>
<td><p>(1),(3)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">gztar</span></code></p></td>
<td><p>gzip 的 tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.gz</span></code>)</p></td>
<td><p>(2)</p></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">bztar</span></code></p></td>
<td><p>bzip2 的 tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.bz2</span></code>)</p></td>
<td></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">xztar</span></code></p></td>
<td><p>xz 的 tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.xz</span></code>)</p></td>
<td></td>
</tr>
<tr class="row-even"><td><p><code class="docutils literal notranslate"><span class="pre">ztar</span></code></p></td>
<td><p>带压缩的 tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar.Z</span></code>)</p></td>
<td><p>(4)</p></td>
</tr>
<tr class="row-odd"><td><p><code class="docutils literal notranslate"><span class="pre">tar</span></code></p></td>
<td><p>tar 文件 (<code class="file docutils literal notranslate"><span class="pre">.tar</span></code>)</p></td>
<td></td>
</tr>
</tbody>
</table>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.5 版更改: </span>添加了对 <code class="docutils literal notranslate"><span class="pre">xztar</span></code> 格式的支持</p>
</div>
<p>注释:</p>
<ol class="arabic simple">
<li><p>默认Windows</p></li>
<li><p>默认 Unix</p></li>
<li><p>需要有外部 <strong class="program">zip</strong> 工具或 <a class="reference internal" href="../library/zipfile.html#module-zipfile" title="zipfile: Read and write ZIP-format archive files."><code class="xref py py-mod docutils literal notranslate"><span class="pre">zipfile</span></code></a> 模块(自 Python 1.6 起是标准 Python 库的一部分)</p></li>
<li><p>需要有 <strong class="program">compress</strong> 程序。 请注意此格式计划要弃用并将在未来的 Python 版本中被移除。</p></li>
</ol>
<p>当使用任意 <code class="docutils literal notranslate"><span class="pre">tar</span></code> 格式 (<code class="docutils literal notranslate"><span class="pre">gztar</span></code>, <code class="docutils literal notranslate"><span class="pre">bztar</span></code>, <code class="docutils literal notranslate"><span class="pre">xztar</span></code>, <code class="docutils literal notranslate"><span class="pre">ztar</span></code><code class="docutils literal notranslate"><span class="pre">tar</span></code>) 时,在 Unix 中你可以指定将为每个归档成员设置的 <code class="docutils literal notranslate"><span class="pre">owner</span></code><code class="docutils literal notranslate"><span class="pre">group</span></code> 名称。</p>
<p>举例来说,如果你希望归档中的全部文件均为 root 所有:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">sdist</span> <span class="o">--</span><span class="n">owner</span><span class="o">=</span><span class="n">root</span> <span class="o">--</span><span class="n">group</span><span class="o">=</span><span class="n">root</span>
</pre></div>
</div>
<section id="specifying-the-files-to-distribute">
<span id="manifest"></span><h2><span class="section-number">4.1. </span>指定要分发的文件<a class="headerlink" href="#specifying-the-files-to-distribute" title="永久链接至标题"></a></h2>
<p>如果你没有显式提供文件列表(或如何生成该列表的说明),则 <strong class="command">sdist</strong> 命令会将一个最小化默认集加入源代码分发版:</p>
<ul class="simple">
<li><p>通过 <code class="docutils literal notranslate"><span class="pre">py_modules</span></code><code class="docutils literal notranslate"><span class="pre">packages</span></code> 选项指明的所有 Python 源文件</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">ext_modules</span></code><code class="docutils literal notranslate"><span class="pre">libraries</span></code> 选项提及的所有 C 源代码文件</p>
</li>
<li><p>通过 <code class="docutils literal notranslate"><span class="pre">scripts</span></code> 选项标识的脚本,参见 <a class="reference internal" href="setupscript.html#distutils-installing-scripts"><span class="std std-ref">安装脚本</span></a></p></li>
<li><p>任何看起来像是测试脚本的文件: <code class="file docutils literal notranslate"><span class="pre">test/test*.py</span></code> (目前Distutils 不会对测试脚本做除了将它们包括到源代码分发版以外的任何操作,但是在未来将会有一个测试 Python 模块分发版的标准)</p></li>
<li><p>任何标准的 README 文件 (<code class="file docutils literal notranslate"><span class="pre">README</span></code>, <code class="file docutils literal notranslate"><span class="pre">README.txt</span></code><code class="file docutils literal notranslate"><span class="pre">README.rst</span></code>), <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> (或任何你指定的安装脚本) 以及 <code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code></p></li>
<li><p>所有匹配 <code class="docutils literal notranslate"><span class="pre">package_data</span></code> 元数据的文件。 参见 <a class="reference internal" href="setupscript.html#distutils-installing-package-data"><span class="std std-ref">安装软件包数据</span></a></p></li>
<li><p>所有匹配 <code class="docutils literal notranslate"><span class="pre">data_files</span></code> 元数据的文件。 参见 <a class="reference internal" href="setupscript.html#distutils-additional-files"><span class="std std-ref">安装其它文件</span></a></p></li>
</ul>
<p>有时这就足够了,但通常你还会希望指定要分发的额外文件。 实现这一点的通常方式是编写一个 <em>声明模板</em>,默认名称为 <code class="file docutils literal notranslate"><span class="pre">MANIFEST.in</span></code>。 声明模板就是一个有关如何生成你的声明文件 <code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code> 的指令列表,也就是要实际包括在你的源代码分发版中的文件的列表。 <strong class="command">sdist</strong> 命令会处理这个模板并基于其指令及其在文件系统中的查找结果生成一个声明文件。</p>
<p>如果你想要制作你自己的声明文件,格式很简单:每行一个文件名,仅限常规文件。 如果你提供你自己的 <code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code>,你必须指明一切:上面描述的默认集将不适用于这种情况。</p>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.1 版更改: </span>现有的已生成 <code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code> 将被生成而无需 <strong class="command">sdist</strong> 来将其修改时间与 <code class="file docutils literal notranslate"><span class="pre">MANIFEST.in</span></code><code class="file docutils literal notranslate"><span class="pre">setup.py</span></code> 的修改时间进行比较。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.1.3 版更改: </span><code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code> 文件以一个表明它们已生成的注释开始。 没有这条注释的文件不会被覆盖或移除。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.2.2 版更改: </span><strong class="command">sdist</strong> 将在不存在 <code class="file docutils literal notranslate"><span class="pre">MANIFEST.in</span></code> 时读取一个 <code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code> 文件,如它以前所做的一样。</p>
</div>
<div class="versionchanged">
<p><span class="versionmodified changed">在 3.7 版更改: </span><code class="file docutils literal notranslate"><span class="pre">README.rst</span></code> 现在已被包括在 distutils 标准 README 列表中。</p>
</div>
<p>声明模板每行都有一个命令,其中每个命令指定了一组源代码发布版中要包括或排除的文件。 举例来说,我们再次关注 Distutils 自己的声明模板:</p>
<div class="highlight-none notranslate"><div class="highlight"><pre><span></span>include *.txt
recursive-include examples *.txt *.py
prune examples/sample?/build
</pre></div>
</div>
<p>其含义应当很清楚:包括发布在根目录中所有匹配 <code class="file docutils literal notranslate"><span class="pre">*.txt</span></code> 的文件,在 <code class="file docutils literal notranslate"><span class="pre">examples</span></code> 目录下任何位置上匹配 <code class="file docutils literal notranslate"><span class="pre">*.txt</span></code><code class="file docutils literal notranslate"><span class="pre">*.py</span></code> 的所有文件,并排除匹配 <code class="file docutils literal notranslate"><span class="pre">examples/sample?/build</span></code> 的所有目录。 所有这些操作都将在标准的包括集 <em>之后</em> 执行,因此你可以通过在声明模板中的显式指令来排除标准集中的文件。 (或者,你也可以使用 <code class="xref std std-option docutils literal notranslate"><span class="pre">--no-defaults</span></code> 选项来完全禁用标准集。) 在声明模板迷你语言中还有一些其他的可用命令;参见 <a class="reference internal" href="commandref.html#sdist-cmd"><span class="std std-ref">创建源码发行包: sdist 命令</span></a> 小节。</p>
<p>声明模板中命令的顺序是很重要的:在初始状态下,我们有如上所述的默认文件列表,而模板中的每个命令将在该文件列表中添加或移除条目。 一旦我们完全处理好声明模板,我们将再移除不应包括在源代码发布版中的文件:</p>
<ul class="simple">
<li><p>Distutils &quot;构建&quot; 目录树中的所有文件 (默认值 <code class="file docutils literal notranslate"><span class="pre">build/</span></code>)</p></li>
<li><p>目录中所有名为 <code class="file docutils literal notranslate"><span class="pre">RCS</span></code>, <code class="file docutils literal notranslate"><span class="pre">CVS</span></code>, <code class="file docutils literal notranslate"><span class="pre">.svn</span></code>, <code class="file docutils literal notranslate"><span class="pre">.hg</span></code>, <code class="file docutils literal notranslate"><span class="pre">.git</span></code>, <code class="file docutils literal notranslate"><span class="pre">.bzr</span></code><code class="file docutils literal notranslate"><span class="pre">_darcs</span></code> 的文件</p></li>
</ul>
<p>现在我们有了完整的文件列表,它已被写入声明以供将来引用,并随后用于构建源代码分发压缩 包。</p>
<p>你可以通过 <code class="xref std std-option docutils literal notranslate"><span class="pre">--no-defaults</span></code> 选项禁用默认的包括文件集,你还可以通过 <code class="xref std std-option docutils literal notranslate"><span class="pre">--no-prune</span></code> 禁用默认的排除文件集。</p>
<p>跟随 Distutils 自己的声明模板,让我们追踪' own manifest template, let's trace how the <strong class="command">sdist</strong> 命令是如何构建要包括在 Distutils 源代码分发版中的文件列表的:</p>
<ol class="arabic simple">
<li><p>包括 <code class="file docutils literal notranslate"><span class="pre">distutils</span></code><code class="file docutils literal notranslate"><span class="pre">distutils/command</span></code> 子目录中的所有 Python 源代码文件(因为与这两个目录对应的包在 setup 脚本的 <code class="docutils literal notranslate"><span class="pre">packages</span></code> 选项中被提及 --- 参见 <a class="reference internal" href="setupscript.html#setup-script"><span class="std std-ref">编写安装脚本</span></a> 一节)</p></li>
<li><p>包括 <code class="file docutils literal notranslate"><span class="pre">README.txt</span></code>, <code class="file docutils literal notranslate"><span class="pre">setup.py</span></code><code class="file docutils literal notranslate"><span class="pre">setup.cfg</span></code> (标准文件)</p></li>
<li><p>包括 <code class="file docutils literal notranslate"><span class="pre">test/test*.py</span></code> (标准文件)</p></li>
<li><p>包括分发根目录下的 <code class="file docutils literal notranslate"><span class="pre">*.txt</span></code> (这将第二次找到 <code class="file docutils literal notranslate"><span class="pre">README.txt</span></code>,但这样的冗余随后会被清除)</p></li>
<li><p>包括 <code class="file docutils literal notranslate"><span class="pre">examples</span></code> 下所有子目录树中匹配 <code class="file docutils literal notranslate"><span class="pre">*.txt</span></code><code class="file docutils literal notranslate"><span class="pre">*.py</span></code> 的任何文件,</p></li>
<li><p>排除从匹配 <code class="file docutils literal notranslate"><span class="pre">examples/sample?/build</span></code> 的目录开始的子目录树中的所有文件 --- 这可能会排除之前两个步骤所包括的文件,因此重要的一点是声明模板中的 <code class="docutils literal notranslate"><span class="pre">prune</span></code> 命令应放在 <code class="docutils literal notranslate"><span class="pre">recursive-include</span></code> 命令之后</p></li>
<li><p>排除整个 <code class="file docutils literal notranslate"><span class="pre">build</span></code> 目录树,以及任何 <code class="file docutils literal notranslate"><span class="pre">RCS</span></code>, <code class="file docutils literal notranslate"><span class="pre">CVS</span></code>, <code class="file docutils literal notranslate"><span class="pre">.svn</span></code>, <code class="file docutils literal notranslate"><span class="pre">.hg</span></code>, <code class="file docutils literal notranslate"><span class="pre">.git</span></code>, <code class="file docutils literal notranslate"><span class="pre">.bzr</span></code> and <code class="file docutils literal notranslate"><span class="pre">_darcs</span></code> 目录</p></li>
</ol>
<p>就像在设置脚本中一样声明模板中的文件和目录名应当总是以斜杠分隔Distutils 将会负责把它们转化为你的系统平台上的标准表示形式。 通过这种方式,声明模板将可跨操作系统移植。</p>
</section>
<section id="manifest-related-options">
<span id="manifest-options"></span><h2><span class="section-number">4.2. </span>声明相关选项<a class="headerlink" href="#manifest-related-options" title="永久链接至标题"></a></h2>
<p>针对 <strong class="command">sdist</strong> 命令的正常操作过程如下:</p>
<ul class="simple">
<li><p>如果声明文件 (默认为 <code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code>) 存在且第一行不为表示它是由 <code class="file docutils literal notranslate"><span class="pre">MANIFEST.in</span></code> 生成的注释,则它会被不加修改地原样使用</p></li>
<li><p>如果声明文件不存在或是在此之前被自动生成的,则读取 <code class="file docutils literal notranslate"><span class="pre">MANIFEST.in</span></code> 并创建声明文件</p></li>
<li><p>如果 <code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code><code class="file docutils literal notranslate"><span class="pre">MANIFEST.in</span></code> 均不存在,则使用默认文件集创建声明文件</p></li>
<li><p>使用当前 <code class="file docutils literal notranslate"><span class="pre">MANIFEST</span></code> (刚生成的或读入的) 中的文件列表创建源代码分发压缩包</p></li>
</ul>
<p>有数个选项可以修改此行为。 首先,使用 <code class="xref std std-option docutils literal notranslate"><span class="pre">--no-defaults</span></code><code class="xref std std-option docutils literal notranslate"><span class="pre">--no-prune</span></code> 来禁用标准的 &quot;包括&quot;&quot;排除&quot; 集。</p>
<p>第二,你可能只是想要(重)生成声明文件,但不想要创建源代码分发包:</p>
<div class="highlight-python3 notranslate"><div class="highlight"><pre><span></span><span class="n">python</span> <span class="n">setup</span><span class="o">.</span><span class="n">py</span> <span class="n">sdist</span> <span class="o">--</span><span class="n">manifest</span><span class="o">-</span><span class="n">only</span>
</pre></div>
</div>
<p><code class="xref std std-option docutils literal notranslate"><span class="pre">-o</span></code><code class="xref std std-option docutils literal notranslate"><span class="pre">--manifest-only</span></code> 的缩写。</p>
</section>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<h3><a href="../contents.html">目录</a></h3>
<ul>
<li><a class="reference internal" href="#">4. 创建源代码分发包</a><ul>
<li><a class="reference internal" href="#specifying-the-files-to-distribute">4.1. 指定要分发的文件</a></li>
<li><a class="reference internal" href="#manifest-related-options">4.2. 声明相关选项</a></li>
</ul>
</li>
</ul>
<h4>上一个主题</h4>
<p class="topless"><a href="configfile.html"
title="上一章"><span class="section-number">3. </span>编写设置脚本的配置文件</a></p>
<h4>下一个主题</h4>
<p class="topless"><a href="builtdist.html"
title="下一章"><span class="section-number">5. </span>创建构建分发版</a></p>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/sourcedist.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</a> |</li>
<li class="right" >
<a href="builtdist.html" title="5. 创建构建分发版"
>下一页</a> |</li>
<li class="right" >
<a href="configfile.html" title="3. 编写设置脚本的配置文件"
>上一页</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.8.20 Documentation</a> &#187;
</li>
<li class="nav-item nav-item-1"><a href="index.html" >分发 Python 模块(遗留版本)</a> &#187;</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>

View File

@@ -0,0 +1,225 @@
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh_CN">
<head>
<meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
<title>上传包到包索引 &#8212; Python 3.8.20 文档</title><meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="../_static/pydoctheme.css" type="text/css" />
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
<script src="../_static/jquery.js"></script>
<script src="../_static/underscore.js"></script>
<script src="../_static/doctools.js"></script>
<script src="../_static/language_data.js"></script>
<script src="../_static/translations.js"></script>
<script src="../_static/sidebar.js"></script>
<link rel="search" type="application/opensearchdescription+xml"
title="在 Python 3.8.20 文档 中搜索"
href="../_static/opensearch.xml"/>
<link rel="author" title="关于这些文档" href="../about.html" />
<link rel="index" title="索引" href="../genindex.html" />
<link rel="search" title="搜索" href="../search.html" />
<link rel="copyright" title="版权所有" href="../copyright.html" />
<link rel="canonical" href="https://docs.python.org/3/distutils/uploading.html" />
<style>
@media only screen {
table.full-width-table {
width: 100%;
}
}
</style>
<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>
</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" />
<label for="menuToggler" class="toggler__label">
<span></span>
</label>
<nav class="nav-content" role="navigation">
<a href="https://www.python.org/" class="nav-logo">
<img src="../_static/py.svg" alt="Logo"/>
</a>
<div class="version_switcher_placeholder"></div>
<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"
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" fill="#444"></path>
</svg>
<input type="text" name="q" aria-label="快速搜索"/>
<input type="submit" value="转向"/>
</form>
</nav>
<div class="menu-wrapper">
<nav class="menu" role="navigation" aria-label="main navigation">
<div class="language_switcher_placeholder"></div>
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/uploading.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</nav>
</div>
</div>
<div id="outdated-warning" style="padding: .5em; text-align: center; background-color: #FFBABA; color: #6A0E0E;">
这个文档所针对的是一个已不再受支持的 Python 旧版本。
你应当升级版本,并阅读
<a href="/3/distutils/uploading.html"> Python 当前稳定版本的文档</a>.
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
accesskey="I">索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
<div class="body" role="main">
<section id="uploading-packages-to-the-package-index">
<h1>上传包到包索引<a class="headerlink" href="#uploading-packages-to-the-package-index" title="永久链接至标题"></a></h1>
<p>供参考的最新 PyPI 文档可以在 <a class="reference internal" href="../distributing/index.html#publishing-python-packages"><span class="std std-ref">阅读 Python 打包用户指南</span></a> 找到。</p>
</section>
</div>
</div>
</div>
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
<div class="sphinxsidebarwrapper">
<div role="note" aria-label="source link">
<h3>本页</h3>
<ul class="this-page-menu">
<li><a href="../bugs.html">报告 Bug</a></li>
<li>
<a href="https://github.com/python/cpython/blob/3.8/Doc/distutils/uploading.rst"
rel="nofollow">显示源代码
</a>
</li>
</ul>
</div>
</div>
</div>
<div class="clearer"></div>
</div>
<div class="related" role="navigation" aria-label="related navigation">
<h3>导航</h3>
<ul>
<li class="right" style="margin-right: 10px">
<a href="../genindex.html" title="总目录"
>索引</a></li>
<li class="right" >
<a href="../py-modindex.html" title="Python 模块索引"
>模块</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.8.20 Documentation</a> &#187;
</li>
<li class="right">
<div class="inline-search" role="search">
<form class="inline-search" action="../search.html" method="get">
<input placeholder="快速搜索" aria-label="快速搜索" type="text" name="q" />
<input type="submit" value="转向" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
|
</li>
</ul>
</div>
<div class="footer">
&copy; <a href="../copyright.html">版权所有</a> 2001-2024, 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 />
<br />
The Python Software Foundation is a non-profit corporation.
<a href="https://www.python.org/psf/donations/">Please donate.</a>
<br />
<br />
最后更新于 12月 09, 2024.
<a href="https://docs.python.org/3/bugs.html">Found a bug</a>?
<br />
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 2.4.4.
</div>
</body>
</html>