python - distutils.core和setuptools有什么区别

  发布于 2022-10-28 07:48

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

from distutils.core import setup

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

from setuptools import setup, find_packages

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

1 个回答
  • 学会看官方文档,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中有这么一句:

    setup = distutils.core.setup

    就是这样。

    2022-10-29 10:34 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有