python - 通过 Pip 从 setup.py 打印一条消息

标签 python pip warnings setuptools

当用户使用 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/

相关文章:

python - 没有名为 sh 的模块

python - 无法在 Python 3.8 中安装 microsoft presidio-analyzer

delphi - dcc32警告UnloadProcs.pas(59):W1035函数“GetType”的返回值可能未定义

c++ - 如何在没有警告的情况下使用 execv()?

c++ - `public` 访问限定符和 `const` ness。 `-Wuninitialized`

Python 日志记录 : how to represent newlines in the format string in a logging config file?

python - 如果文件不存在则创建一个文件,否则什么也不做

java - 斯坦福依赖关系转换工具

python - 使用模板覆盖更改 django 管理列表中的模型对象 url

python - 何时在 setup.py 中使用 pip 需求文件与 install_requires?