【发布时间】:2017-10-22 17:10:08
【问题描述】:
我尝试配置我的包,以便在安装过程中执行脚本。因此,我继承了 setuptools.command install 并创建了我的自定义类ActionOnInstall 来在安装包时做一些事情。此类通过 setuptools setup() 参数 cmdclass 调用,如 here 所述。
这种 setup.py 文件的最小示例如下所示
from setuptools import find_packages, setup
from setuptools.command.install import install
class ActionOnInstall(install):
def run(self):
print("Call install.run(self) works!")
install.run(self)
setup(name='name',
cmdclass={
'install': ActionOnInstall})
通过执行构建包
pip3 install <path-to-dir-with-setup.py>
成功运行但不执行ActionOnInstall.run() 中指定的命令。通过
python3 setup.py install
执行ActionOnInstall.run()中指定的命令。
然后,我发现自己在问:这两种安装软件包的方法的实际区别是什么。我知道,就像其他帖子告诉我们的那样,pip 让安装包的工作变得更轻松。但是没有解释这两种方法如何区别对待setup() 的cmdclass 参数。因此,我非常感谢你们的来信。
【问题讨论】:
标签: python installation pip package setuptools