用pycharm自动生成的setup文件,使用的是distutils.core里的setup
from distutils.core import setup
但我看很多人写的setup,用的是setuptools
from setuptools import setup, find_packages
这个distutils和setuptools分别是什么背景,怎么同样功能出现两个包呢?
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
学会看官方文档,
distutils的介绍(distutils - python2):也就是说,整个
distutils包就是负责建立Python扩展模块的安装器用的。然后是文档的第二段:
看见了吧,大部分
Python用户会使用更先进的setuptools模块,然后文档下面列了几点setuptools的优点,这里就不贴出来了。那么为什么
Pycharm会用distutils呢?不是说setuptools更强大么?原因很简单:
distutils是Python标准模块,setuptools是第三方模块。而Pycharm不知道你是否安装了setuptools,为避免不必要的麻烦,当然要用标准模块了。然后我们看一下
setuptools.setup到底是个什么东西,在setuptools/__init__.py中有这么一句:就是这样。