如何从setup.py中抑制PEP440Warning?

eud*_*xos 7 python warnings setuptools

我正在运行,python setup.py或者python3 setup.py哪个给了我PEP440Warning不相关的包,我不打算解决:

/usr/lib/python3/dist-packages/pkg_resources/__init__.py:2512: PEP440Warning: 'python-apt (0.9.3.11build1)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
  PEP440Warning,
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:2512: PEP440Warning: 'apturl (0.5.2ubuntu6)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
  PEP440Warning,
/usr/lib/python3/dist-packages/pkg_resources/__init__.py:2512: PEP440Warning: 'ufw (0.34-rc-0ubuntu5)' is being parsed as a legacy, non PEP 440, version. You may find odd behavior and sort order. In particular it will be sorted as less than 0.0. It is recommend to migrate to PEP 440 compatible versions.
  PEP440Warning,
Run Code Online (Sandbox Code Playgroud)

我想沉默这个警告,我尝试了许多-W开关的变种而没有任何成功:

  • 匹配模块:-W ignore:::pkg_resources:→那里有警告,没有关于无效-W规范的消息
  • 匹配类名:-W ignore::PEP440Warning::Invalid -W option ignored: unknown warning category: 'PEP440Warning'
  • 匹配完全限定的类名:-W ignore::pkg_resources.PEP440Warning::Invalid -W option ignored: invalid module name: 'pkg_resources'(??)
  • 匹配消息测试:-W ignore:PEP 440:::→那里有警告,没有关于无效-W规范的消息
  • 匹配所有警告:-W ignore →那里的警告

最后一次尝试让我相信,由于某种原因,命令行开关根本没有被尊重.为什么?

Jav*_*ier 0

如果使用-W ignore仍然显示警告,setuptools则要么没有使用该warnings模块来生成该输出,要么正在启动一个没有相同选项的新Python。

尝试使用这样的环境变量:export PYTHONWARNINGS="ignore"

如果它仍然显示警告,那么我会检查源代码以了解该警告是如何生成的。