Python 在使用setuptools构建包时,如何避免收到无用的警告?

Python 在使用setuptools构建包时,如何避免收到无用的警告?,python,setuptools,Python,Setuptools,似乎setuptools触发了各种各样的警告,这些警告实际上是零值的,我想在它们对持续集成过程进行垃圾处理时消除它们,从而更难发现真正的警告 以下是我确实想摆脱的: python setup.py -q bdist_wheel warning: no previously-included files matching '__pycache__' found under directory '*' warning: no previously-included files matching '*

似乎setuptools触发了各种各样的警告,这些警告实际上是零值的,我想在它们对持续集成过程进行垃圾处理时消除它们,从而更难发现真正的警告

以下是我确实想摆脱的:

python setup.py -q bdist_wheel
warning: no previously-included files matching '__pycache__' found under directory '*'
warning: no previously-included files matching '*.pyc' found under directory '*'
warning: no previously-included files matching '*.pyo' found under directory '*'
warning: no previously-included files matching '*.orig' found under directory '*'
warning: no files found matching '*.md' under directory 'releases'
warning: no files found matching '*.rst' under directory 'releases'
warning: no files found matching '*.json' under directory 'releases'
warning: no previously-included files matching '*' found under directory 'examples/node_modules'
no previously-included directories found matching 'examples/node_modules'
warning: build_py: byte-compiling is disabled, skipping.

warning: install_lib: byte-compiling is disabled, skipping.

似乎所有这些都是由文件引起的,但那里的条件确实有原因存在,而这显然不是当排除模式没有找到匹配的文件时生成警告的原因

目前,我只找到了一个解决此问题的方法:

导出PYTHONDONTWRITEBYTECODE=

这将避免在构建过程中收到这些恼人的警告。

我使用makefile来构建我的项目,我必须在顶部添加以下行:

unexport PYTHONDONTWRITEBYTECODE

在shell中,还必须
取消设置pythontwritebytecode
。将其从
1
设置为
0
将不起作用。不过我使用的是
zsh
,所以上面的答案可能在其他地方也适用

此外,您可以将
-B
直接传递给
python
以禁用字节编译,但环境变量优先于它(至少在我使用的python3版本中是-
3.6.8
)。不过,我看不到强制启用字节编译的选项

最后,您可以将
--help
传递给大多数
setup.py
命令,以获取它们支持的标志的信息。例如,
build\u py
install\u lib
支持
--compile/-c
--no-compile
标志应该可以帮助您进行细粒度控制,尽管根据我的经验,环境变量仍然优先