每当我通过 Python v3.10.4 执行任何 Python 代码(无论是否在 Visual Studio Code v1.74.2 中进行调试)时,除了代码的正常输出之外,我还会在“调试控制台”窗口中获得如下所示的输出。否则,我的所有 Python 程序此时都可以正常工作并按预期运行。
1 HIToolbox 0x00007ff81116c0c2 _ZN15MenuBarInstance22RemoveAutoShowObserverEv + 30
2 HIToolbox 0x00007ff8111837e3 SetMenuBarObscured + 115
3 HIToolbox 0x00007ff81118a29e _ZN13HIApplication11FrontUILostEv + 34
4 HIToolbox 0x00007ff811183622 _ZN13HIApplication15HandleActivatedEP14OpaqueEventRefhP15OpaqueWindowPtrh + 508
5 HIToolbox 0x00007ff81117d950 _ZN13HIApplication13EventObserverEjP14OpaqueEventRefPv + 182
6 HIToolbox 0x00007ff811145bd2 _NotifyEventLoopObservers + 153
7 HIToolbox 0x00007ff81117d3e6 AcquireEventFromQueue + 494
8 HIToolbox 0x00007ff81116c5a4 ReceiveNextEventCommon + 725
9 HIToolbox 0x00007ff81116c2b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
10 AppKit 0x00007ff80a973f33 _DPSNextEvent + 909
11 AppKit 0x00007ff80a972db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
12 AppKit 0x00007ff80a9653f7 -[NSApplication run] + 586
13 _macosx.cpython-310-darwin.so 0x0000000110407e22 show + 162
14 Python 0x0000000100bb7595 cfunction_vectorcall_NOARGS + 101
15 Python 0x0000000100c9101f call_function + 175
16 Python 0x0000000100c8a2c4 _PyEval_EvalFrameDefault + 34676
17 Python 0x0000000100c801df _PyEval_Vector + 383
18 Python 0x0000000100c9101f call_function + 175
19 Python 0x0000000100c8a2c4 _PyEval_EvalFrameDefault + 34676
20 Python 0x0000000100c801df _PyEval_Vector + 383
21 Python 0x0000000100b53f61 method_vectorcall + 481
22 Python 0x0000000100c8a4f2 _PyEval_EvalFrameDefault + 35234
23 Python 0x0000000100c801df _PyEval_Vector + 383
24 Python 0x0000000100c9101f call_function + 175
25 Python 0x0000000100c8a2c4 _PyEval_EvalFrameDefault + 34676
26 Python 0x0000000100c801df _PyEval_Vector + 383
27 Python 0x0000000100cf536d pyrun_file + 333
28 Python 0x0000000100cf4b2d _PyRun_SimpleFileObject + 365
29 Python 0x0000000100cf417f _PyRun_AnyFileObject + 143
30 Python 0x0000000100d20047 pymain_run_file_obj + 199
31 Python 0x0000000100d1f815 pymain_run_file + 85
32 Python 0x0000000100d1ef9e pymain_run_python + 334
33 Python 0x0000000100d1ee07 Py_RunMain + 23
34 Python 0x0000000100d201e2 pymain_main + 50
35 Python 0x0000000100d2048a Py_BytesMain + 42
36 dyld 0x00007ff80741b310 start + 2432
- 尽管据我所知,我的任何 Python 程序中都没有任何内容可以直接导致这些行出现在调试控制台窗口中,但为什么这些行会出现在调试控制台窗口中?
- 它们有何帮助?如果需要,如何使用它们?
- 我怎样才能防止它们默认出现?
我结帐了有关 Python 调试的 Visual Studio Code 文档 https://code.visualstudio.com/docs/python/debugging但找不到任何可以解释这些线条的东西。我在 macOS Ventura v13.1 上运行 Visual Studio Code。
截至 2023 年 1 月 2 日更新
我发现我的初始帖子中不需要的输出是由 Python 程序中的 matplotlib.pyplot.show 函数触发的。即使我运行如下简单的程序,我也会得到该输出:
import matplotlib.pyplot as plt
x = [1, 2, 3]
y = [1, 2, 3]
plt.plot(x, y)
plt.show()
当我从上面的代码中删除 plt.show() 时,36 行不需要的输出不会出现,但图形也不会显示。同样,除了不需要的输出之外,我的所有带有 show 函数的 Python 程序似乎都能正常工作,包括由 show 函数触发的图形显示。我的 Mac 上安装了 Matplotlib 3.5.2。
如果我直接通过命令行运行相同的程序(假设 Python 程序的名称是test.py
):
python3 test.py
但当我跑步时却不是test.py
通过 IDLE(Python 的集成开发和学习环境)或 Jupyter Notebook 中的代码。
我可以从 Python 程序中删除 show 函数以避免不需要的输出,但图表将不会出现,我更喜欢使用 show 函数而不是临时解决方案。
截至 2023 年 1 月 4 日更新
I was 在 Matplotlib 论坛上建议 https://discourse.matplotlib.org/t/show-function-triggering-unwanted-output/23442这可能是 macOS Ventura v13.1 问题,因为最近开始报告在 macOS Ventura v13.1 下执行的不同程序出现类似问题。一位用户报告遇到类似的输出使用 Tkinter 的代码 https://www.reddit.com/r/learnpython/comments/zyukpk/weird_output_in_terminal_while_using_tkinter/和另一个使用名为 mpv 的视频播放器时 https://github.com/mpv-player/mpv/issues/11018.
该问题也与 macOS Ventura v13.1 有关,这并非难以置信,但我不知道如何解决,我的问题仍然存在。
截至 2023 年 1 月 6 日更新
将 Matplotlib 升级到 v3.6.2 但不需要的输出问题尚未解决。
截至 2023 年 1 月 8 日更新
尝试了 Matplotlib v3.6.2 和 Python v3.11.1。不需要的输出问题仍然存在。
截至 2023 年 1 月 15 日更新
已将此问题作为错误报告给 GitHub 上的 Matplotlib 开发人员:“[Bug]:显示函数触发不需要的额外输出#24997 https://github.com/matplotlib/matplotlib/issues/24997"
截至 2023 年 1 月 16 日更新
我发现只有当“系统设置”->“桌面和扩展坞”->“菜单栏”下的“自动隐藏和显示菜单栏”选项设置为Always
(这是我的设置)或on Desktop Only
。如果我将该选项设置为,则不会出现不需要的输出In Full Screen Only
or Never
.
截至 2023 年 1 月 18 日更新
GitHub 上的 Matplotlib 和 Python 开发人员都认为,他们可以重现的不需要的输出是 macOS Ventura 13.1 中的错误造成的,因此他们对此无能为力。
有关详细信息,请参阅我提到的在 GitHub 上为 Matplotlib 提交的错误报告以及我后来在 GitHub 上再次通过 Python/CPython 为 Tkinter 提交的错误报告之后的相应讨论:Tkinter 在最新的 macOS 中导致不需要的输出 https://github.com/python/cpython/issues/101067”。我还被告知,针对后者,反馈助理报告现已提交给苹果公司,内容涉及已发现的错误。
截至 2023 年 1 月 25 日更新
今天我将 Mac 上的 macOS 升级到了 Ventura 13.2(2 月中旬发布时进一步升级到了 Ventura 13.2.1)。没有任何变化,只是运行小程序时不需要的输出现在相当长(85 行)。和以前一样,程序运行良好,否则如果我更改 Mac 的菜单栏设置,则不会出现不需要的输出,例如,Never
.