distribution、distutils、setuptools 和 distutils2 之间的区别?

发布于 2024-11-15 20:51:58 字数 551 浏览 4 评论 0原文

我正在尝试

将开源库移植到 Python 3。(SymPy,如果有人想知道的话。)

所以,我需要在构建 Python 3 时自动运行 2to3。为此,我需要使用 distribute。因此,我需要移植当前系统,(根据文档测试)是 distutils


问题

不幸的是,我不确定这些模块之间有什么区别 - distutilsdistributesetuptools。该文档最好是粗略的,因为它们似乎都是彼此的分叉,旨在在大多数情况下兼容(但实际上不是全部)......等等,等等。


问题

有人可以解释一下这些差异吗?我应该使用什么?最现代的解决方案是什么? (顺便说一句,我还希望获得一些有关移植到 Distribute 的指南,但这有点超出了问题的范围......)

The Situation

I’m trying to port an open-source library to Python 3. (SymPy, if anyone is wondering.)

So, I need to run 2to3 automatically when building for Python 3. To do that, I need to use distribute. Therefore, I need to port the current system, which (according to the doctest) is distutils.

The Problem

Unfortunately, I’m not sure what’s the difference between these modules—distutils, distribute, setuptools. The documentation is sketchy as best, as they all seem to be a fork of one another, intended to be compatible in most circumstances (but actually, not all)…and so on, and so forth.

The Question

Could someone explain the differences? What am I supposed to use? What is the most modern solution? (As an aside, I’d also appreciate some guide on porting to Distribute, but that’s a tad beyond the scope of the question…)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

谁把谁当真 2024-11-22 20:51:58

截至 2022 年 5 月,这个问题的大多数其他答案都已经过时了好几年。当您遇到有关 Python 打包问题的建议时,请记住查看发布日期,不要相信过时的信息。

Python 打包用户指南值得一读。每个页面都会显示“最后更新”日期,因此您可以检查手册的最新版本,而且内容相当全面。事实上,它托管在 Python 软件基金会的 python.org 子域上,这更增加了它的可信度。 项目摘要页面在这里特别相关。

工具摘要:

以下是 Python 打包情况的摘要:

支持的工具:

已弃用/废弃的工具:

  • distutils 仍然包含在 Python 标准库中,但从 Python 3.10 开始被视为已弃用。它对于简单的 Python 发行版很有用,但缺乏功能。它引入了可以在 setup.py 脚本中导入的 distutils Python 包。

  • distributesetuptools 的一个分支。它共享相同的命名空间,因此如果您安装了 Distribute,import setuptools 实际上会导入随 Distribute 分发的包。 Distribute 已合并回 Setuptools 0.7,因此您不再需要使用 Distribute。其实Pypi上的版本只是安装Setuptools的兼容层。

  • distutils2 试图充分利用 distutilssetuptoolsdistribute 并成为Python标准库中包含的标准工具。我们的想法是,distutils2 将针对旧 Python 版本进行分发,而 distutils2 将在 Python 3.3 中重命名为 packaging,其中将包含它在其标准库中。然而,这些计划并没有按预期进行,目前,distutils2 是一个废弃的项目。最新版本发布于 2012 年 3 月,其 Pypi 主页终于更新以反映其已消亡的情况。


其他:

还有其他工具,如果您有兴趣,请阅读Python中的Project Summaries包装用户指南。我不会将它们全部列出,以免重复该页面,并保持答案与问题匹配,该问题仅涉及 distributedistutilssetuptools< /code> 和 distutils2

建议:

如果所有这些对您来说都是新的,并且您不知道从哪里开始,我建议学习 setuptools 以及 pipvirtualenv,它们都可以很好地协同工作。

如果您正在研究 virtualenv,您可能会对这个问题感兴趣:之间有什么区别>venvpyvenvpyenvvirtualenvvirtualenvwrapper、等等?。 (是的,我知道,我和你一起呻吟。)

As of May 2022, most of the other answers to this question are several years out-of-date. When you come across advice on Python packaging issues, remember to look at the date of publication, and don't trust out-of-date information.

The Python Packaging User Guide is worth a read. Every page has a "last updated" date displayed, so you can check the recency of the manual, and it's quite comprehensive. The fact that it's hosted on a subdomain of python.org of the Python Software Foundation just adds credence to it. The Project Summaries page is especially relevant here.

Summary of tools:

Here's a summary of the Python packaging landscape:

Supported tools:

Deprecated/abandoned tools:

  • distutils is still included in the standard library of Python, but is considered deprecated as of Python 3.10. It is useful for simple Python distributions, but lacks features. It introduces the distutils Python package that can be imported in your setup.py script.

  • distribute was a fork of setuptools. It shared the same namespace, so if you had Distribute installed, import setuptools would actually import the package distributed with Distribute. Distribute was merged back into Setuptools 0.7, so you don't need to use Distribute any more. In fact, the version on Pypi is just a compatibility layer that installs Setuptools.

  • distutils2 was an attempt to take the best of distutils, setuptools and distribute and become the standard tool included in Python's standard library. The idea was that distutils2 would be distributed for old Python versions, and that distutils2 would be renamed to packaging for Python 3.3, which would include it in its standard library. These plans did not go as intended, however, and currently, distutils2 is an abandoned project. The latest release was in March 2012, and its Pypi home page has finally been updated to reflect its death.

Others:

There are other tools, if you are interested, read Project Summaries in the Python Packaging User Guide. I won't list them all, to not repeat that page, and to keep the answer matching the question, which was only about distribute, distutils, setuptools and distutils2.

Recommendation:

If all of this is new to you, and you don't know where to start, I would recommend learning setuptools, along with pip and virtualenv, which all work very well together.

If you're looking into virtualenv, you might be interested in this question: What is the difference between venv, pyvenv, pyenv, virtualenv, virtualenvwrapper, etc?. (Yes, I know, I groan with you.)

甜中书 2024-11-22 20:51:58

我是 distutils 维护者和 distutils2/打包贡献者。我在 ConFoo 2011 上做了一个关于 Python 打包的演讲,这些天我正在编写它的扩展版本。它尚未发布,因此以下摘录应该有助于定义事物。

  • Distutils 是用于打包的标准工具。它可以很好地满足简单的需求,但受到限制并且扩展起来并不容易。

  • Setuptools 是一个出于填补 distutils 功能缺失和探索新方向的愿望而诞生的项目。在某些子社区中,它是事实上的标准。它使用了 Python 核心开发人员不赞成的猴子补丁和魔法。

  • Distribute 是Setuptools 的一个分支,开发人员认为它的开发速度太慢并且不可能发展它,因此开始了它的开发。当同一组启动 distutils2 时,它的开发速度显着减慢。 2013 年 8 月更新:distribute 合并回 setuptools 并停止使用。

  • Distutils2 是一个新的 distutils 库,最初是作为 distutils 代码库的一个分支,具有从安装工具中汲取的好想法(其中一些在 PEP 中进行了深入讨论),以及受启发的基本安装程序点。 用于导入 Distutils2 的实际名称是 Python 3.3+ 标准库中的 packaging,或 2.4+ 和 3.1–3.2 中的 distutils2。 (向后移植很快就会推出。) Distutils2 没有发布 Python 3.3,它被搁置了。

更多信息:

我希望尽快完成我的指南,它将包含有关每个库的优点和缺点的更多信息以及过渡指南。

I’m a distutils maintainer and distutils2/packaging contributor. I did a talk about Python packaging at ConFoo 2011 and these days I’m writing an extended version of it. It’s not published yet, so here are excerpts that should help define things.

  • Distutils is the standard tool used for packaging. It works rather well for simple needs, but is limited and not trivial to extend.

  • Setuptools is a project born from the desire to fill missing distutils functionality and explore new directions. In some subcommunities, it’s a de facto standard. It uses monkey-patching and magic that is frowned upon by Python core developers.

  • Distribute is a fork of Setuptools that was started by developers feeling that its development pace was too slow and that it was not possible to evolve it. Its development was considerably slowed when distutils2 was started by the same group. 2013-August update: distribute is merged back into setuptools and discontinued.

  • Distutils2 is a new distutils library, started as a fork of the distutils codebase, with good ideas taken from setup tools (of which some were thoroughly discussed in PEPs), and a basic installer inspired by pip. The actual name you use to import Distutils2 is packaging in the Python 3.3+ standard library, or distutils2 in 2.4+ and 3.1–3.2. (A backport will be available soon.) Distutils2 did not make the Python 3.3 release, and it was put on hold.

More info:

I hope to finish my guide soon, it will contain more info about each library’s strong and weak points and a transition guide.

黯然 2024-11-22 20:51:58

注意:答案已弃用,分发现已过时。自从 Python 包装管理局成立并做了很多清理工作以来,这个答案就不再有效了。


是的,你明白了。 :-o 我认为目前首选的软件包是 Distribute,它是 setuptools 的一个分支,它们是 distutils(原始打包系统)的扩展。 setuptools 没有得到维护,因此被分叉并重命名,但是安装时它使用 setuptools 的包名称!我认为大多数 Python 开发人员现在都使用 Distribute,我可以肯定地说我是这么做的。

NOTE: Answer deprecated, Distribute now obsolete. This answer is no longer valid since the Python Packaging Authority was formed and has done a lot of work cleaning this up.


Yep, you got it. :-o I think at this time the preferred package is Distribute, which is a fork of setuptools, which are an extension of distutils (the original packaging system). Setuptools was not being maintained so is was forked and renamed, however when installed it uses the package name of setuptools! I think most Python developers now use Distribute, and I can say for sure that I do.

寄与心 2024-11-22 20:51:58

我意识到我已经回答了你的第二个问题,但没有解决你原来问题中未经质疑的假设:

我正在尝试将一个开源库(SymPy,如果有人想知道的话)移植到 Python 3。
为此,我需要在构建 Python 3 时自动运行 2to3。

可能,而不需要。其他策略在 http://docs.python.org/dev/howto/pyporting

为此,我需要使用分发,

可能:) distutils 支持代码(而不是文档字符串)的构建时 2to3 转换,其方式与分发的方式不同: http://docs.python.org/dev/howto/pyporting#during-installation

I realize that I have replied to your secondary question without addressing unquestioned assumptions in your original problem:

I'm trying to port an open-source library (SymPy, if anyone is wondering) to Python 3. To
do this, I need to run 2to3 automatically when building for Python 3.

You may, not need. Other strategies are described at http://docs.python.org/dev/howto/pyporting

To do that, I need to use distribute,

You may :) distutils supports build-time 2to3 conversion for code (not docstrings), in a different manner that distribute’s: http://docs.python.org/dev/howto/pyporting#during-installation

网名女生简单气质 2024-11-22 20:51:58

在 2014 年底更新了这个问题,幸运的是 Python 打包混乱已经被 Continuum 的“conda”极大地清理了包管理器。

特别是,conda 可以快速创建 conda“环境”。您可以使用不同版本的 Python 配置环境。例如:

conda create -n py34 python=3.4 anaconda

conda create -n py26 python=2.6 anaconda

将创建两个(“py34”或“py26”)Python 环境不同版本的Python。

之后,您可以使用特定版本的 Python 调用环境:

source activate

在您必须处理不同版本的 Python 的情况下,此功能似乎特别有用。

此外,conda 具有以下功能:

  • 与 Python 无关
  • 跨平台
  • 无需管理员权限
  • 智能依赖管理(通过 SAT 求解器)
  • 很好地处理可能需要链接的 C、Fortran 和系统级库

最后一点尤其重要如果您从事科学计算领域。

Updating this question in late 2014 where fortunately the Python packaging chaos has been greatly cleaned up by Continuum's "conda" package manager.

In particular, conda quickly enables the creation of conda "environments". You can configure your environments with different versions of Python. For example:

conda create -n py34 python=3.4 anaconda

conda create -n py26 python=2.6 anaconda

will create two ("py34" or "py26") Python environments with different versions of Python.

Afterwards you can invoke the environment with the specific version of Python with:

source activate <env name>

This feature seems especially useful in your case where you are having to deal with different version of Python.

Moreover, conda has the following features:

  • Python agnostic
  • Cross platform
  • No admin privileges required
  • Smart dependency management (by way of a SAT solver)
  • Nicely deals with C, Fortran and system level libraries that you may have to link against

That last point is especially important if you are in the scientific computing arena.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文