当用户使用 pip
时,有什么方法可以让用户从 setup.py 中看到消息和/或警告吗?
我的包使用自定义安装命令。 setup.py的结构如下:
from setuptools import setup
from setuptools.command.install import install
import warnings
import sys
class CustomInstallCommand(install):
def run(self):
install.run(self)
sys.stdout.write('My message.\n')
sys.stdout.flush()
warnings.warn('My warning.', UserWarning)
setup(name='blub',
version='0.1',
description='blah',
packages=['blub'],
cmdclass={'install': CustomInstallCommand})
当我运行python setup.py install
时,我在输出中看到自定义打印消息和警告。
但是,如果我运行 pip install .
,我只会得到这个:
C:\Users\ae\Software\SomeModule>pip install .
Processing c:\users\ae\software\somemodule
Building wheels for collected packages: blub
Building wheel for blub (setup.py) ... done
Created wheel for blub: filename=blub-0.1-cp37-none-any.whl size=1115 sha256=51c91c5b449673e3be5dd7382cd12f59cb38021167ba3a0b3634214419c61bcb
Stored in directory: C:\Users\ae\AppData\Local\Temp\pip-ephem-wheel-cache-575zecpf\wheels\81\5f\73\46e55517a1e0973939e9578945ff104b6e0193cfaed649e206
Successfully built blub
Installing collected packages: blub
Found existing installation: blub 0.1
Uninstalling blub-0.1:
Successfully uninstalled blub-0.1
Successfully installed blub-0.1
最佳答案
尝试:pip install 。 -v
-v 是详细信息,它显示详细消息。默认情况下是关闭的。用户不想看到它。如果您将其显示为错误,他们可能会感到困惑,但如果它不是错误,而您将其显示为错误,那么他们可能会感到困惑。
进一步帮助的链接:How to print warnings and errors when using setuptools (pip)
关于python - 通过 Pip 从 setup.py 打印一条消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59965769/