gpt4 book ai didi

python - pip3 和 `python3 setup.py install` 关于 cmdclass 参数的区别

转载 作者:太空狗 更新时间:2023-10-29 20:51:05 33 4
gpt4 key购买 nike

我试图配置我的包,以便在安装过程中执行脚本。因此,我继承了 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() 中指定的命令。更直接的调用这个setup.py

python3 setup.py install 

执行 ActionOnInstall.run() 中指定的命令。

然后,我发现自己在问:这两种安装包的方法的实际区别是什么。我知道,就像其他帖子告诉我们的那样,pip 让软件包安装变得更轻松。但是没有解释这两种方法如何以不同方式处理 setup()cmdclass 参数。因此,非常感谢收到你们的来信。

最佳答案

pip 调用您的 setup.py 但它重定向 stdout/stderr。测试 pip 下的 setup.py 写入固定位置的文件:

class ActionOnInstall(install):
def run(self):
print("Call install.run(self) works!", file=open('/tmp/debug.log', 'w'))
install.run(self)

pip install 之后查看/tmp/debug.log。

关于python - pip3 和 `python3 setup.py install` 关于 cmdclass 参数的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44123098/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com