发行版,distutils,setuptools和distutils2之间的区别? [英] Differences between distribute, distutils, setuptools and distutils2?

查看:97
本文介绍了发行版,distutils,setuptools和distutils2之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将开放源代码库移植到Python3.(如果有人在想的话,是 SymPy .)

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

因此,在为Python 3构建时,我需要自动运行2to3.为此,我需要使用distribute.因此,我需要移植当前系统(根据doctest)为distutils.

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.


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

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.


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

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…)

推荐答案

截至2020年3月,该问题的大多数其他答案已经过时了几年.当您遇到有关Python包装问题的建议时,请记住查看发布日期,并且不要相信过时的信息.

As of March 2020, 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.

Python打包用户指南值得一读.每个页面上显示的是最后更新"日期,因此您可以检查手册的最新性,而且内容很全面.它托管在Python Software Foundation的python.org的子域中,这本身就增加了可信度. 项目摘要页在这里尤其重要.

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.

以下是Python封装环境的摘要:

Here's a summary of the Python packaging landscape:

  • distutils 仍然是使用Python打包的标准工具.它包含在标准库(Python 2和Python 3)中.它对于简单的Python发行版很有用,但缺少功能.它介绍了可以在setup.py脚本中导入的distutils Python软件包.

  • distutils is still the standard tool for packaging in Python. It is included in the standard library (Python 2 and Python 3). 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.

  • Official docs | distutils section of Python Package User Guide

setuptools 是为了克服Distutils的局限性而开发的,并且不包含在标准库中.它引入了一个名为easy_install的命令行实用程序.它还介绍了可以在setup.py脚本中导入的setuptools Python软件包,以及可以在您的代码中导入以查找随发行版一起安装的数据文件的pkg_resources Python软件包.它的陷阱之一是它对distutils Python程序包进行了猴子修补.它应该与pip一起很好地工作. 它会看到常规版本.

setuptools was developed to overcome Distutils' limitations, and is not included in the standard library. It introduced a command-line utility called easy_install. It also introduced the setuptools Python package that can be imported in your setup.py script, and the pkg_resources Python package that can be imported in your code to locate data files installed with a distribution. One of its gotchas is that it monkey-patches the distutils Python package. It should work well with pip. It sees regular releases.

  • Official docs | Pypi page | GitHub repo | setuptools section of Python Package User Guide

scikit-build 是一个改进的构建系统生成器,在内部使用CMake来构建编译的Python扩展.由于scikit-build不是基于distutils的,因此它实际上没有任何限制.当存在ninja-build时,scikit-build的大型项目的编译速度比其他项目快三倍.它应该与pip一起使用.

  • Official docs | Pypi page | GitHub repo | scikit-build section of Python Package User Guide

distlib 是一个提供诸如pip之类的高级工具使用的功能的库.

distlib is a library that provides functionality that is used by higher level tools like pip.

  • Official Docs | Pypi page | Bitbucket repo | distlib section of Python Package User Guide

packaging 也是一个库,提供了诸如pipsetuptools

  • Official Docs | Pypi page | GitHub repo | packaging section of Python Package User Guide
  • distribute setuptools的一个分支.它共享相同的名称空间,因此,如果您安装了Distribute,则import setuptools实际上将导入随Distribute分发的程序包. Distribute已合并回Setuptools 0.7 ,因此您无需再使用Distribute.实际上,Pypi上的版本只是安装Setuptools的兼容层.

  • 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 试图充分利用distutilssetuptoolsdistribute的优势,并成为Python标准库中包含的标准工具.想法是distutils2将为旧的Python版本分发,而distutils2对于Python 3.3将被重命名为packaging,并将其包含在其标准库中.这些计划没有按计划进行,但是,目前, distutils2是一个废弃的项目 .最新版本于2012年3月发布,其Pypi主页最终已更新以反映其死亡.

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.

还有其他工具,如果您有兴趣的话,请阅读《 Python打包用户指南》中的项目摘要. .我不会列出所有内容,也不会重复该页面,也不会使答案与问题保持匹配,该问题仅与distributedistutilssetuptoolsdistutils2有关.

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.

如果这一切对您来说都是新手,并且您不知道从哪里开始,我建议您学习setuptools 以及pipvirtualenv,它们都可以工作在一起很好.

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.

如果您正在研究virtualenv,您可能会对以下问题感兴趣: venv与有什么区别, pyvenvpyenvvirtualenvvirtualenvwrapper等?. (是的,我知道,我和你在一起吟.)

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.)

这篇关于发行版,distutils,setuptools和distutils2之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆