- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们使用第三方开源工具,它会生成警告:
DeprecationWarning: The compiler package is deprecated and removed in Python 3.x.
如何在不修改第三方代码的情况下抑制此警告?
我知道如何使用 warnings.filter()
但我无法使用它:我从命令行调用 py.test
,因此没有单一源代码我的代码行在创建警告之前执行。
围绕控制台脚本创建包装器不是一个选项。
最佳答案
您可以添加调用 warnings.filter()
的 usercustomize
或 sitecustomize
模块。它将在解释器启动时加载。
Python provides two hooks to let you customize it:
sitecustomize
andusercustomize
. To see how it works, you need first to find the location of your user site-packages directory. Start Python and run this code:>>> import site
>>> site.getusersitepackages()
'/home/user/.local/lib/python2.7/site-packages'Now you can create a file named
usercustomize.py
in that directory and put anything you want in it. It will affect every invocation of Python, unless it is started with the-s
option to disable the automatic import.
sitecustomize
works in the same way, but is typically created by an administrator of the computer in the global site-packages directory, and is imported beforeusercustomize
. See the documentation of thesite
module for more details.
您可以使用PYTHONUSERBASE
environment variable来影响Python的外观。 ,因此您可以在此处将 Python 指向每个项目的 usercustomize.py
文件,前提是您考虑将路径 lib/python/site-packages
添加到基础中:
$ python -m site --user-site
/Users/someuser/Library/Python/2.7/lib/python/site-packages
$ PYTHONUSERBASE=/foo/bar python -m site --user-site
/foo/bar/lib/python/site-packages
在上面的示例中,将 PYTHONUSERBASE
设置为 /foo/bar
,Python 将加载 /foo/bar/lib/python/site-packages/usercustomize.py
(如果存在)。
在 Python virtualenv 中,使用自定义的 site.py
文件,该文件基于 Python 2.6 之前的 site.py
;此版本省略了 getusersitepackages()
函数。如果文件 lib/pythonX.X/no-global-site-packages.txt
存在,则usercustomize
模块将不会被导入。您必须改用虚拟环境 lib/python/site-packages
目录中的 sitecustomize.py
文件。
关于python - 无需修改第三方代码即可抑制警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24572689/
我收到警告 Circular dependency detected! 在 Angular 6 中,我知道为什么会出现这个问题,但这根本不是问题。 我目前正在使用 SVG,按照我的逻辑,我会防止可能出
我试图抑制 clang/gcc 中地址清理程序发出的警告 我的源文件如下所示: int foo(){ double bar[] = {7,8}; return bar[3]; } int ma
我在微服务架构中有一个应用程序。该应用程序从不同的源获取数据,并且从其他各种应用程序获得许多不同的错误响应。某些异常(例如404-Not Found异常)可以引发并返回给最终用户,但其他异常(错误请求
我喜欢使用 readxl包裹。但是,我一直将它用作 RMarkdown 文档和一些 read_excel() 文档的一部分。读入文件时的消息在进行分析时很有用,但在尝试呈现分析时则不然。所以问题是,在
当我编译 JAXB 模式时,生成的类用通用 Javadoc 注释进行修饰。 是否有可能以某种方式抑制生成这些评论? 最佳答案 Annotation to disable JavaDocs Not if
我正在尝试运行专为 Vuze 设计的插件使用Java。为此,我使用这样的命令: /home/x/jre1.6.0_14/bin/java -Dazureus.config.path=/home/x/p
所以 - 我正在使用库 pyminizip - 这是我发现创建受密码保护的 zip 文件的唯一方法。当我使用它时,我收到一个弃用警告:“#”格式需要 PY_SSIZE_T_CLEAN。 现在,我无法控
这个问题在这里已经有了答案: Is ticklabel_format broken? (1 个回答) 关闭 2 年前。 我是 geopandas 的新手,我正在尝试用常规记数法而非科学记数法绘制带有
我从 Valgrind 得到以下日志: MPK ==5263== 4 bytes in 1 blocks are still reachable in loss record 1 of 84 ==52
有什么方法可以抑制 mediawiki 中的贬低警告吗?例如我在个人 wiki 站点的某些页面顶部收到此消息。 Deprecated: Use of MWNamespace::getSubject w
我正在使用 ScheduledThreadPoolExecutor 执行定期任务。 执行必须是周期性的,而不是固定的延迟。 我遇到了以下问题:考虑一个任务的时间为 1 分钟。如果任务需要 5 分钟才能
我是使用 RScaLAPACK 的 R 新手,每次我生成一个新的进程网格时,我都会收到一条消息。 > sla.gridInit(2) [1] "RScaLAPACK:Process Grid Init
我目前正在使用包 readr 读取文件.这个想法是使用 read_delim逐行读取以查找非结构化数据文件中的最大列数。代码输出有 parsing问题。我知道这些并将在导入后处理列类型。有没有办法关闭
所以我试图防止 fatal error 阻止我的脚本运行 所以我将错误报告设置为0: error_reporting(0); 然后我添加了一些垃圾代码.. junk code~~~~trolololo
在使用 summary() 函数(例如,stata 中的 absorb() 函数的等价物)时,是否有一种方法可以抑制线性模型中固定效应的系数。例如,我希望汇总函数只输出截距和 x,而不是因子的系数和标
如何抑制 SBT 的调试消息?它们被记录到标准输出,所以运行一个项目会产生这个: $ cat src/main/scala/Hello.scala object Hello { def main(
有没有办法抑制 Doxygen 对特定文件发出“未记录”警告?我的项目有几个自动生成的代码头,导致它抛出成百上千的错误,难以筛选。 最佳答案 如 documentation 中所述,有一个配置选项。
R的eHOF包中的HOF函数会自动生成进度条。函数中没有关闭进度条的参数。 有什么办法可以抑制函数外的进度条的生成? (我正在应用该功能数百次,目前进度条除了淹没我的屏幕外没有任何作用。) 最佳答案
随着所有 SDK 的出现,能够方便地针对多个 SDK 和平台进行构建。然而,从 3.2 跳到 3.0,甚至偶尔跳到 2.x,我经常收到涉及已更改或被取代的方法的弃用警告: warning: 'UIKe
我创建了一个 PowerShell 脚本,该脚本将为 Cisco Meraki 添加 VPN 连接。 脚本本身按预期运行,但如果发生错误,则会出现“已完成”弹出窗口,并在 PS 窗口中显示错误消息。
我是一名优秀的程序员,十分优秀!