python - distutils.core和setuptools有什么区别
阿神
阿神 2017-04-18 09:27:25
0
1
1275

用pycharm自动生成的setup文件,使用的是distutils.core里的setup

from distutils.core import setup

但我看很多人写的setup,用的是setuptools

from setuptools import setup, find_packages

这个distutils和setuptools分别是什么背景,怎么同样功能出现两个包呢?

阿神
阿神

闭关修行中......

全部回复(1)
巴扎黑

学会看官方文档,distutils的介绍(distutils - python2):distutils的介绍(distutils - python2):

The distutils package provides support for building and installing additional modules into a Python installation. The new modules may be either 100%-pure Python, or may be extension modules written in C, or may be collections of Python packages which include modules coded in both Python and C.

也就是说,整个distutils包就是负责建立Python扩展模块的安装器用的。
然后是文档的第二段:

Most Python users will not want to use this module directly, but instead use the cross-version tools maintained by the Python Packaging Authority. In particular, setuptools is an enhanced alternative to distutils that provides:

看见了吧,大部分Python用户会使用更先进的setuptools模块,然后文档下面列了几点setuptools的优点,这里就不贴出来了。

那么为什么Pycharm会用distutils呢?不是说setuptools更强大么?

原因很简单:
distutilsPython标准模块,setuptools是第三方模块。而Pycharm不知道你是否安装了setuptools,为避免不必要的麻烦,当然要用标准模块了。

然后我们看一下setuptools.setup到底是个什么东西,在setuptools/__init__.py

The distutils package provides support for building and installing additional modules into a Python installation. The new modules may be either 100%-pure Python, or may be extension modules written in C, or may be collections of Python packages which include modules coded in both Python and C.

也就是说,整个distutils包就是负责建立Python扩展模块的安装器用的。
然后是文档的第二段:🎜
🎜Most Python users will not want to use this module directly, but instead use the cross-version tools maintained by the Python Packaging Authority. In particular, setuptools is an enhanced alternative to distutils that provides:🎜
🎜看见了吧,大部分Python用户会使用更先进的setuptools模块,然后文档下面列了几点setuptools的优点,这里就不贴出来了。🎜 🎜那么为什么Pycharm会用distutils呢?不是说setuptools更强大么?🎜 🎜原因很简单:
distutilsPython标准模块,setuptools是第三方模块。而Pycharm不知道你是否安装了setuptools,为避免不必要的麻烦,当然要用标准模块了。🎜 🎜然后我们看一下setuptools.setup到底是个什么东西,在setuptools/__init__.py中有这么一句:🎜
setup = distutils.core.setup
🎜就是这样。🎜
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!