问题描述
Python具有令人困惑的工具历史,可用于打包和描述项目:这些工具包括标准库中的distutils
,distribute
,distutils2
和setuptools
(也许还有更多).看来,distribute
和distutils2
已停产,取而代之的是setuptools
,这留下了两个相互竞争的标准.
据我了解,setuptools
提供的选项(例如,声明依赖项,测试等)比distutils
多得多,但是它没有包含在Python标准库中(还可以吗?).
Python打包用户指南 [ 1 ]现在推荐:
并解释:
但是,查看各种项目的 setup.py 文件表明,这似乎并不是一个实际的标准.许多软件包仍使用distutils
,而支持setuptools
的软件包通常将setuptools
与distutils
混合使用.通过执行后备导入:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
接着尝试找到一种写可由setuptools
和distutils
都安装的安装程序的方法.由于distutils
在设置功能中不支持依赖关系,因此通常包括多种容易出错的依赖关系检查方式.
为什么人们仍会付出更多的努力来支持distutils
-是setuptools
不在标准库中的事实的唯一原因吗? distutils
的优点是什么?编写仅支持setuptools
的 setup.py 文件有什么缺点.
看看这个SO问题.它很好地说明了所有打包方法,并可能在一定程度上帮助您回答问题: distribute,distutils,setuptools和distutils2之间的区别?
因此,正如您所看到的,setuptools应该比distutils更受青睐,我看到了您的问题来自何处,但是我看不到distutils会很快失去支持,因为简单地说,它在许多情况下与某些情况一起使用.受欢迎的旧版程序.正如您可能知道的那样,在旧版程序中更改此类操作可能会很痛苦,并且会遇到很多问题,例如不兼容,这将导致开发人员不得不重写源代码.因此,distutils是标准python库的一部分,而setuptools不是.因此,如果您正在当今时代创建python程序,请使用setuptools,但是请记住,没有distutils,setuptools将永远不存在.
Python has a confusing history of tools that can be used to package and describe projects: these include distutils
in the Standard Library, distribute
, distutils2
, and setuptools
(and maybe more). It appears that distribute
and distutils2
were discontinued in favor of setuptools
, which leaves two competing standards.
To my understanding setuptools
offers far more options (e.g. declaring dependencies, tests, etc.) than distutils
, however it is not included in the Python standard library (yet?).
The Python Packaging User Guide[1] recommends now:
And explains:
However, looking into various project's setup.py files reveals that this does not seem to be an actual standard. Many packages still use distutils
and those that support setuptools
often mix setuptools
with distutils
e.g. by doing a fallback import:
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
Followed by an attempt to find a way to write a setup that can be installed by both setuptools
and distutils
. This often includes various ways of error-prone dependency checking, since distutils
does not support dependencies in the setup function.
Why are people still making the extra effort to support distutils
- is the fact that setuptools
is not in the standard library the only reason? What are the advantages of distutils
and are there any drawbacks of writing setup.py files that only support setuptools
.
Have a look at this SO question. It explains all the packaging methods very well, and might help answer your question to some extent: Differences between distribute, distutils, setuptools and distutils2?
So, as you can see setuptools should be preferred to distutils, and I see where your question comes from, however I don't see distutils losing support anytime soon, as, simply put, it is used in many cases with some popular legacy programs. And as you probably know changing these sorts of things in legacy programs can be quite a pain and come with quite a few problems, for example incompatibilities, which would then lead to the developer having to rewrite the source code. So there is that, and also the fact that distutils is a part of the standard python library whereas setuptools is not. So, if you are creating a python program, in this day and age, use setuptools, however keep in mind that without distutils, setuptools would have never existed.
这篇关于setuptools vs. distutils:为什么distutils仍然是一回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!