“Python/docs/3.9/distributing/index”的版本间差异

来自菜鸟教程
Python/docs/3.9/distributing/index
跳转至:导航、​搜索
(autoload)
 
(Page commit)
 
第1行: 第1行:
 +
{{DISPLAYTITLE:分发 Python 模块 — Python 文档}}
 
<div id="distributing-python-modules" class="section">
 
<div id="distributing-python-modules" class="section">
  
 
<span id="distributing-index"></span>
 
<span id="distributing-index"></span>
= Distributing Python Modules =
+
= 分发 Python 模块 =
  
; Email
+
; 电子邮件
 
: [mailto:distutils-sig%40python.org distutils-sig<span>@</span>python<span>.</span>org]
 
: [mailto:distutils-sig%40python.org distutils-sig<span>@</span>python<span>.</span>org]
  
As a popular open source development project, Python has an active
+
作为一个流行的开源开发项目,Python 拥有一个由贡献者和用户组成的活跃支持社区,这些社区还可以让其他 Python 开发人员根据开源许可条款使用他们的软件。
supporting community of contributors and users that also make their software
 
available for other Python developers to use under open source license terms.
 
  
This allows Python users to share and collaborate effectively, benefiting
+
这允许 Python 用户有效地共享和协作,从其他人已经为常见(有时甚至是罕见的!)问题创建的解决方案中受益,并可能将他们自己的解决方案贡献给公共池。
from the solutions others have already created to common (and sometimes
 
even rare!) problems, as well as potentially contributing their own
 
solutions to the common pool.
 
  
This guide covers the distribution part of the process. For a guide to
+
本指南涵盖了流程的分发部分。 有关安装其他 Python 项目的指南,请参阅 [[../../installing/index#installing-index|安装指南]]
installing other Python projects, refer to the
 
[[../../installing/index#installing-index|<span class="std std-ref">installation guide</span>]].
 
  
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
For corporate and other institutional users, be aware that many
+
对于企业和其他机构用户,请注意,许多组织在使用和贡献开源软件方面都有自己的政策。 在使用 Python 提供的分发和安装工具时,请考虑这些策略。
organisations have their own policies around using and contributing to
 
open source software. Please take such policies into account when making
 
use of the distribution and installation tools provided with Python.
 
  
  
第33行: 第24行:
 
<div id="key-terms" class="section">
 
<div id="key-terms" class="section">
  
== Key terms ==
+
== 关键术语 ==
  
* the [https://pypi.org Python Packaging Index] is a public repository of open source licensed packages made available for use by other Python users
+
* [https://pypi.org Python 包索引] 是开源许可包的公共存储库,可供其他 Python 用户使用
* the [https://www.pypa.io/ Python Packaging Authority] are the group of developers and documentation authors responsible for the maintenance and evolution of the standard packaging tools and the associated metadata and file format standards. They maintain a variety of tools, documentation and issue trackers on both [https://github.com/pypa GitHub] and [https://bitbucket.org/pypa/ Bitbucket].
+
* [https://www.pypa.io/ Python Packaging Authority] 是一组开发人员和文档作者,负责标准打包工具以及相关元数据和文件格式标准的维护和发展。 他们在 [https://github.com/pypa GitHub] [https://bitbucket.org/pypa/ Bitbucket] 上维护各种工具、文档和问题跟踪器。
* [[../../library/distutils#module-distutils|<code>distutils</code>]] is the original build and distribution system first added to the Python standard library in 1998. While direct use of [[../../library/distutils#module-distutils|<code>distutils</code>]] is being phased out, it still laid the foundation for the current packaging and distribution infrastructure, and it not only remains part of the standard library, but its name lives on in other ways (such as the name of the mailing list used to coordinate Python packaging standards development).
+
* [[../../library/distutils#module-distutils|distutils]] 是 1998 年首次添加到 Python 标准库中的原始构建和分发系统。 虽然直接使用 [[../../library/distutils#module-distutils|distutils]] 正在逐步淘汰,但它仍然为当前的打包和分发基础设施奠定了基础,它不仅仍然是标准库的一部分,而且它的名字在其他方面仍然存在(例如作为用于协调 Python 打包标准开发的邮件列表的名称)。
* [https://setuptools.readthedocs.io/en/latest/ setuptools] is a (largely) drop-in replacement for [[../../library/distutils#module-distutils|<code>distutils</code>]] first published in 2004. Its most notable addition over the unmodified [[../../library/distutils#module-distutils|<code>distutils</code>]] tools was the ability to declare dependencies on other packages. It is currently recommended as a more regularly updated alternative to [[../../library/distutils#module-distutils|<code>distutils</code>]] that offers consistent support for more recent packaging standards across a wide range of Python versions.
+
* [https://setuptools.readthedocs.io/en/latest/ setuptools] 是 2004 年首次发布的 [[../../library/distutils#module-distutils|distutils]] 的(主要)直接替代品。 与未修改的 [[../../library/distutils#module-distutils|distutils]] 工具相比,它最显着的新增功能是能够声明对其他包的依赖关系。 目前推荐它作为 [[../../library/distutils#module-distutils|distutils]] 的更定期更新的替代品,它为各种 Python 版本的更新的打包标准提供一致的支持。
* [https://wheel.readthedocs.io/ wheel] (in this context) is a project that adds the <code>bdist_wheel</code> command to [[../../library/distutils#module-distutils|<code>distutils</code>]]/[https://setuptools.readthedocs.io/en/latest/ setuptools]. This produces a cross platform binary packaging format (called &quot;wheels&quot; or &quot;wheel files&quot; and defined in <span id="index-0" class="target"></span>[https://www.python.org/dev/peps/pep-0427 '''PEP 427''']) that allows Python libraries, even those including binary extensions, to be installed on a system without needing to be built locally.
+
* [https://wheel.readthedocs.io/ wheel](在此上下文中)是将 <code>bdist_wheel</code> 命令添加到 [[../../library/distutils#module-distutils|distutils]]/[https://setuptools.readthedocs.io/en/latest/ setuptools] 的项目。 这会产生一种跨平台二进制打包格式(称为“轮子”或“轮子文件”,并在 <span id="index-0" class="target"></span>[https://www.python.org/dev/peps/pep-0427 PEP 427] 中定义)允许安装 Python 库,甚至包括二进制扩展的库在系统上,而无需在本地构建。
  
  
第45行: 第36行:
 
<div id="open-source-licensing-and-collaboration" class="section">
 
<div id="open-source-licensing-and-collaboration" class="section">
  
== Open source licensing and collaboration ==
+
== 开源许可和协作 ==
  
In most parts of the world, software is automatically covered by copyright.
+
在世界大部分地区,软件自动受版权保护。 这意味着其他开发人员需要明确许可才能复制、使用、修改和重新分发软件。
This means that other developers require explicit permission to copy, use,
 
modify and redistribute the software.
 
  
Open source licensing is a way of explicitly granting such permission in a
+
开源许可是一种以相对一致的方式明确授予此类许可的方式,允许开发人员通过免费提供各种问题的通用解决方案来有效地共享和协作。 这使许多开发人员可以腾出更多时间专注于针对其特定情况相对独特的问题。
relatively consistent way, allowing developers to share and collaborate
 
efficiently by making common solutions to various problems freely available.
 
This leaves many developers free to spend more time focusing on the problems
 
that are relatively unique to their specific situation.
 
  
The distribution tools provided with Python are designed to make it
+
Python 提供的分发工具旨在使开发人员可以相当简单地将自己的贡献回馈给该公共软件池,如果他们选择这样做的话。
reasonably straightforward for developers to make their own contributions
 
back to that common pool of software if they choose to do so.
 
  
The same distribution tools can also be used to distribute software within
+
相同的分发工具也可用于在组织内分发软件,无论该软件是否作为开源软件发布。
an organisation, regardless of whether that software is published as open
 
source software or not.
 
  
  
第69行: 第50行:
 
<div id="installing-the-tools" class="section">
 
<div id="installing-the-tools" class="section">
  
== Installing the tools ==
+
== 安装工具 ==
  
The standard library does not include build tools that support modern
+
标准库不包括支持现代 Python 打包标准的构建工具,因为核心开发团队发现,即使在旧版本的 Python 上,拥有一致工作的标准工具也很重要。
Python packaging standards, as the core development team has found that it
 
is important to have standard tools that work consistently, even on older
 
versions of Python.
 
  
The currently recommended build and distribution tools can be installed
+
当前推荐的构建和分发工具可以通过在命令行调用 <code>pip</code> 模块来安装:
by invoking the <code>pip</code> module at the command line:
 
  
 
<div class="highlight-python3 notranslate">
 
<div class="highlight-python3 notranslate">
第83行: 第60行:
 
<div class="highlight">
 
<div class="highlight">
  
<pre>python -m pip install setuptools wheel twine</pre>
+
<syntaxhighlight lang="python3">python -m pip install setuptools wheel twine</syntaxhighlight>
  
 
</div>
 
</div>
第90行: 第67行:
 
<div class="admonition note">
 
<div class="admonition note">
  
注解
+
笔记
  
For POSIX users (including Mac OS X and Linux users), these instructions
+
对于 POSIX 用户(包括 macOS 和 Linux 用户),这些说明假定使用 [[../../glossary#term-virtual-environment|虚拟环境]]
assume the use of a [[../../glossary#term-virtual-environment|<span class="xref std std-term">virtual environment</span>]].
 
  
For Windows users, these instructions assume that the option to
+
对于 Windows 用户,这些说明假定在安装 Python 时选择了调整系统 PATH 环境变量的选项。
adjust the system PATH environment variable was selected when installing
 
Python.
 
  
  
 
</div>
 
</div>
The Python Packaging User Guide includes more details on the [https://packaging.python.org/guides/tool-recommendations/#packaging-tool-recommendations currently
+
Python Packaging User Guide 包含有关 [https://packaging.python.org/guides/tool-recommendations/#packaging-tool-recommendations 当前推荐工具] 的更多详细信息。
recommended tools].
 
  
  
第109行: 第82行:
  
 
<span id="publishing-python-packages"></span><span id="index-1"></span>
 
<span id="publishing-python-packages"></span><span id="index-1"></span>
== Reading the Python Packaging User Guide ==
+
== 阅读 Python 打包用户指南 ==
  
The Python Packaging User Guide covers the various key steps and elements
+
Python 打包用户指南涵盖了创建和发布项目所涉及的各种关键步骤和元素:
involved in creating and publishing a project:
 
  
* [https://packaging.python.org/tutorials/distributing-packages/ Project structure]
+
* [https://packaging.python.org/tutorials/packaging-projects/#packaging-python-projects 项目结构]
* [https://packaging.python.org/tutorials/distributing-packages/#packaging-your-project Building and packaging the project]
+
* [https://packaging.python.org/tutorials/packaging-projects/#creating-the-package-files 构建和打包项目]
* [https://packaging.python.org/tutorials/distributing-packages/#uploading-your-project-to-pypi Uploading the project to the Python Packaging Index]
+
* [https://packaging.python.org/tutorials/packaging-projects/#uploading-the-distribution-archives 将项目上传到 Python Package Index]
* [https://packaging.python.org/specifications/pypirc/ The .pypirc file]
+
* [https://packaging.python.org/specifications/pypirc/ .pypirc 文件]
  
  
第123行: 第95行:
 
<div id="how-do-i" class="section">
 
<div id="how-do-i" class="section">
  
== How do I...? ==
+
== 我如何能…? ==
  
These are quick answers or links for some common tasks.
+
这些是一些常见任务的快速答案或链接。
  
 
<div id="choose-a-name-for-my-project" class="section">
 
<div id="choose-a-name-for-my-project" class="section">
  
=== ... choose a name for my project? ===
+
=== ...为我的项目选择一个名称? ===
  
This isn't an easy topic, but here are a few tips:
+
这不是一个简单的话题,但这里有一些提示:
  
* check the Python Packaging Index to see if the name is already in use
+
* 检查 Python 包索引以查看名称是否已被使用
* check popular hosting sites like GitHub, Bitbucket, etc to see if there is already a project with that name
+
* 检查流行的托管站点,如 GitHub、Bitbucket 等,看看是否已经有一个具有该名称的项目
* check what comes up in a web search for the name you're considering
+
* 检查您正在考虑的名称的网络搜索中出现的内容
* avoid particularly common words, especially ones with multiple meanings, as they can make it difficult for users to find your software when searching for it
+
* 避免使用特别常见的词,尤其是具有多重含义的词,因为它们会使用户在搜索时难以找到您的软件
  
  
第142行: 第114行:
 
<div id="create-and-distribute-binary-extensions" class="section">
 
<div id="create-and-distribute-binary-extensions" class="section">
  
=== ... create and distribute binary extensions? ===
+
=== ... 创建和分发二进制扩展? ===
  
This is actually quite a complex topic, with a variety of alternatives
+
这实际上是一个相当复杂的主题,有多种替代方案可供选择,具体取决于您要实现的目标。 有关更多信息和建议,请参阅 Python Packaging User Guide。
available depending on exactly what you're aiming to achieve. See the
 
Python Packaging User Guide for more information and recommendations.
 
  
 
<div class="admonition seealso">
 
<div class="admonition seealso">
  
参见
+
也可以看看
  
[https://packaging.python.org/guides/packaging-binary-extensions/ Python Packaging User Guide: Binary Extensions]
+
[https://packaging.python.org/guides/packaging-binary-extensions/ Python 打包用户指南:二进制扩展]
  
  
第162行: 第132行:
  
 
</div>
 
</div>
 +
<div class="clearer">
  
[[Category:Python 3.9 中文文档]]
+
 
 +
 
 +
</div>
 +
 
 +
[[Category:Python 3.9 文档]]

2021年10月31日 (日) 04:50的最新版本

分发 Python 模块

电子邮件
distutils-sig@python.org

作为一个流行的开源开发项目,Python 拥有一个由贡献者和用户组成的活跃支持社区,这些社区还可以让其他 Python 开发人员根据开源许可条款使用他们的软件。

这允许 Python 用户有效地共享和协作,从其他人已经为常见(有时甚至是罕见的!)问题创建的解决方案中受益,并可能将他们自己的解决方案贡献给公共池。

本指南涵盖了流程的分发部分。 有关安装其他 Python 项目的指南,请参阅 安装指南

笔记

对于企业和其他机构用户,请注意,许多组织在使用和贡献开源软件方面都有自己的政策。 在使用 Python 提供的分发和安装工具时,请考虑这些策略。


关键术语

  • Python 包索引 是开源许可包的公共存储库,可供其他 Python 用户使用
  • Python Packaging Authority 是一组开发人员和文档作者,负责标准打包工具以及相关元数据和文件格式标准的维护和发展。 他们在 GitHubBitbucket 上维护各种工具、文档和问题跟踪器。
  • distutils 是 1998 年首次添加到 Python 标准库中的原始构建和分发系统。 虽然直接使用 distutils 正在逐步淘汰,但它仍然为当前的打包和分发基础设施奠定了基础,它不仅仍然是标准库的一部分,而且它的名字在其他方面仍然存在(例如作为用于协调 Python 打包标准开发的邮件列表的名称)。
  • setuptools 是 2004 年首次发布的 distutils 的(主要)直接替代品。 与未修改的 distutils 工具相比,它最显着的新增功能是能够声明对其他包的依赖关系。 目前推荐它作为 distutils 的更定期更新的替代品,它为各种 Python 版本的更新的打包标准提供一致的支持。
  • wheel(在此上下文中)是将 bdist_wheel 命令添加到 distutils/setuptools 的项目。 这会产生一种跨平台二进制打包格式(称为“轮子”或“轮子文件”,并在 PEP 427 中定义)允许安装 Python 库,甚至包括二进制扩展的库在系统上,而无需在本地构建。


开源许可和协作

在世界大部分地区,软件自动受版权保护。 这意味着其他开发人员需要明确许可才能复制、使用、修改和重新分发软件。

开源许可是一种以相对一致的方式明确授予此类许可的方式,允许开发人员通过免费提供各种问题的通用解决方案来有效地共享和协作。 这使许多开发人员可以腾出更多时间专注于针对其特定情况相对独特的问题。

Python 提供的分发工具旨在使开发人员可以相当简单地将自己的贡献回馈给该公共软件池,如果他们选择这样做的话。

相同的分发工具也可用于在组织内分发软件,无论该软件是否作为开源软件发布。


安装工具

标准库不包括支持现代 Python 打包标准的构建工具,因为核心开发团队发现,即使在旧版本的 Python 上,拥有一致工作的标准工具也很重要。

当前推荐的构建和分发工具可以通过在命令行调用 pip 模块来安装:

python -m pip install setuptools wheel twine

笔记

对于 POSIX 用户(包括 macOS 和 Linux 用户),这些说明假定使用 虚拟环境

对于 Windows 用户,这些说明假定在安装 Python 时选择了调整系统 PATH 环境变量的选项。


Python Packaging User Guide 包含有关 当前推荐工具 的更多详细信息。


阅读 Python 打包用户指南

Python 打包用户指南涵盖了创建和发布项目所涉及的各种关键步骤和元素:


我如何能…?

这些是一些常见任务的快速答案或链接。

...为我的项目选择一个名称?

这不是一个简单的话题,但这里有一些提示:

  • 检查 Python 包索引以查看名称是否已被使用
  • 检查流行的托管站点,如 GitHub、Bitbucket 等,看看是否已经有一个具有该名称的项目
  • 检查您正在考虑的名称的网络搜索中出现的内容
  • 避免使用特别常见的词,尤其是具有多重含义的词,因为它们会使用户在搜索时难以找到您的软件


... 创建和分发二进制扩展?

这实际上是一个相当复杂的主题,有多种替代方案可供选择,具体取决于您要实现的目标。 有关更多信息和建议,请参阅 Python Packaging User Guide。