如何从setup.py?

时间:2015-10-22 12:23:51

标签: python warnings setuptools

我正在运行python setup.pypython3 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,

我想沉默这个警告,我尝试了-W switch的多种变体,但没有取得任何成功:

  • 匹配模块:-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→警告

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

1 个答案:

答案 0 :(得分:0)

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

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

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