Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: MacOSX - Show function triggering unwanted additional output #24997

Closed
apaksoy opened this issue Jan 15, 2023 · 15 comments
Closed

[Bug]: MacOSX - Show function triggering unwanted additional output #24997

apaksoy opened this issue Jan 15, 2023 · 15 comments

Comments

@apaksoy
Copy link

apaksoy commented Jan 15, 2023

Bug summary

The matplotlib.pyplot.show function leads to some unwanted output which is about 30 or so lines of text when included in any of my Python programs and run under the macOS (Ventura 13.1) command line interface with the following command (suppose name of the program is test.py)

python3 test.py 

or through Visual Studio Code.

Other than the unwanted output, the programs work correctly including any chart or charts triggered by the show function. When I remove the show function from the program and run it again, the unwanted output disappears but then the chart is not displayed as well.

The unwanted output does not appear when the same program is run using IDLE, Python’s Integrated Development and Learning Environment, or the code in it from within a Jupyter notebook in Visual Studio Code.

Code for reproduction

import matplotlib.pyplot as plt

x = [1, 2, 3]
y = [1, 2, 3]
plt.plot(x, y)

plt.show()

Actual outcome

I am pasting below only the unwanted output which comes out at the same time the chart is displayed. The simple chart produced by the program comes out as expected otherwise.

1   HIToolbox                           0x00007ff8156c4726 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 102
2   HIToolbox                           0x00007ff8156c42b8 _ZN15MenuBarInstance14EnableAutoShowEv + 52
3   HIToolbox                           0x00007ff815668908 SetMenuBarObscured + 408
4   HIToolbox                           0x00007ff8156684ca _ZN13HIApplication15HandleActivatedEP14OpaqueEventRefhP15OpaqueWindowPtrh + 164
5   HIToolbox                           0x00007ff815662996 _ZN13HIApplication13EventObserverEjP14OpaqueEventRefPv + 252
6   HIToolbox                           0x00007ff81562abd2 _NotifyEventLoopObservers + 153
7   HIToolbox                           0x00007ff8156623e6 AcquireEventFromQueue + 494
8   HIToolbox                           0x00007ff8156515a4 ReceiveNextEventCommon + 725
9   HIToolbox                           0x00007ff8156512b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
10  AppKit                              0x00007ff80ee58f33 _DPSNextEvent + 909
11  AppKit                              0x00007ff80ee57db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
12  AppKit                              0x00007ff80ee4a3f7 -[NSApplication run] + 586
13  _macosx.cpython-311-darwin.so       0x0000000104629482 show + 162
14  Python                              0x000000010123f3f6 cfunction_vectorcall_NOARGS + 86
15  Python                              0x00000001013074cf _PyEval_EvalFrameDefault + 60223
16  Python                              0x000000010130d690 _PyEval_Vector + 128
17  Python                              0x00000001011ddcb6 method_vectorcall + 454
18  Python                              0x000000010130a70a _PyEval_EvalFrameDefault + 73082
19  Python                              0x00000001012f764a PyEval_EvalCode + 282
20  Python                              0x000000010137d818 pyrun_file + 248
21  Python                              0x000000010137d0b4 _PyRun_SimpleFileObject + 292
22  Python                              0x000000010137c68b _PyRun_AnyFileObject + 155
23  Python                              0x00000001013a527a pymain_run_file_obj + 234
24  Python                              0x00000001013a4b65 pymain_run_file + 85
25  Python                              0x00000001013a4460 Py_RunMain + 2272
26  Python                              0x00000001013a53eb pymain_main + 43
27  Python                              0x00000001013a5f0a Py_BytesMain + 42
28  dyld                                0x00007ff80b900310 start + 2432

Expected outcome

None of this unwanted output should appear.

Additional information

There is nothing in the code that should cause the unwanted output under normal conditions. I have started having this issue after upgrading macOS from Monterey 12.6.1 to Ventura 13.1. Under macOS Ventura 13.1, I have tried Python 3.10.4 and 3.11.1 along with Matplotlib 3.5.2 and 3.6.2 and keep getting the same unwanted output.

Operating system

macOS 13.1

Matplotlib Version

3.6.2

Matplotlib Backend

MacOSX

Python version

3.11.1

Jupyter version

No response

Installation

pip

@oscargus
Copy link
Contributor

oscargus commented Jan 15, 2023

Thank you for reporting this. It looks very much like a stack trace that is printed from an unhandled exception (i.e. when the program "crashes"). Although, it seems like the actual exception is missing and if I understand correctly, the program is working.

We do test on MacOSX, but I am not sure which version, so it maybe related to 13.1. Several developers also use OSX, but, again, I am not aware of their OS version (but hope that they will clarify it, so I update the title a bit).

A possible workaround for now is to use another backend (you seem to be using the macosx backend, as evident from the line starting with 13). Try something like:

import matplotlib
matplotlib.use('tkagg')

(See https://matplotlib.org/stable/users/explain/backends.html for more info on backends.)

Edit: it seems like all OSX tests are running on 12-series (although named macosx-latest), so it may very well be a 13-series issue.

@oscargus oscargus changed the title [Bug]: Show function triggering unwanted additional output [Bug]: MacOSX - Show function triggering unwanted additional output Jan 15, 2023
@jklymak
Copy link
Member

jklymak commented Jan 15, 2023

On 13.1, I cannot replicate with

conda create -n boo matplotlib numpy python=3.11
conda activate boo
python -c "import matplotlib.pyplot as plt; fig, ax = plt.subplots(); ax.plot(range(10)); plt.show()"

This is python 3.11.0, because that is what conda offers.

@apaksoy
Copy link
Author

apaksoy commented Jan 16, 2023

@oscargus Thx for the explanation and the suggestion.

You are right that I am using the MacOSX backend and the small program in my original post is working fine outside the unwanted output.

When I change the backend to tkagg via the matplotlib.use function as you suggested, I get the following unwanted output when I run the program through the macOS command line interface. As before, the program runs fine otherwise but the unwanted output seems to be getting longer with the tkagg backend.

1   HIToolbox                           0x00007ff8156c4726 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 102
2   HIToolbox                           0x00007ff8156c42b8 _ZN15MenuBarInstance14EnableAutoShowEv + 52
3   HIToolbox                           0x00007ff815668908 SetMenuBarObscured + 408
4   HIToolbox                           0x00007ff8156684ca _ZN13HIApplication15HandleActivatedEP14OpaqueEventRefhP15OpaqueWindowPtrh + 164
5   HIToolbox                           0x00007ff815662996 _ZN13HIApplication13EventObserverEjP14OpaqueEventRefPv + 252
6   HIToolbox                           0x00007ff81562abd2 _NotifyEventLoopObservers + 153
7   HIToolbox                           0x00007ff8156623e6 AcquireEventFromQueue + 494
8   HIToolbox                           0x00007ff8156513ec ReceiveNextEventCommon + 285
9   HIToolbox                           0x00007ff8156512b3 _BlockUntilNextEventMatchingListInModeWithFilter + 70
10  AppKit                              0x00007ff80ee58f33 _DPSNextEvent + 909
11  AppKit                              0x00007ff80ee57db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
12  libtk8.6.dylib                      0x0000000110f927af TkMacOSXEventsCheckProc + 329
13  libtcl8.6.dylib                     0x0000000111253773 Tcl_DoOneEvent + 306
14  libtk8.6.dylib                      0x0000000110f89f60 -[TKApplication(TKInit) applicationDidFinishLaunching:] + 191
15  CoreFoundation                      0x00007ff80bd043f4 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 137
16  CoreFoundation                      0x00007ff80bd9e43a ___CFXRegistrationPost_block_invoke + 88
17  CoreFoundation                      0x00007ff80bd9e389 _CFXRegistrationPost + 536
18  CoreFoundation                      0x00007ff80bcd7919 _CFXNotificationPost + 735
19  Foundation                          0x00007ff80cb11f2c -[NSNotificationCenter postNotificationName:object:userInfo:] + 82
20  AppKit                              0x00007ff80ee60c74 -[NSApplication _postDidFinishNotification] + 305
21  AppKit                              0x00007ff80ee609c6 -[NSApplication _sendFinishLaunchingNotification] + 208
22  AppKit                              0x00007ff80ee5932f _DPSNextEvent + 1929
23  AppKit                              0x00007ff80ee57db4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 1219
24  libtk8.6.dylib                      0x0000000110f925e0 TkMacOSXEventsSetupProc + 155
25  libtcl8.6.dylib                     0x0000000111253728 Tcl_DoOneEvent + 231
26  libtk8.6.dylib                      0x0000000110f8a5a1 TkpInit + 393
27  libtk8.6.dylib                      0x0000000110efe387 Initialize + 2402
28  _tkinter.cpython-311-darwin.so      0x0000000105b9074b Tcl_AppInit + 91
29  _tkinter.cpython-311-darwin.so      0x0000000105b90439 Tkapp_New + 585
30  _tkinter.cpython-311-darwin.so      0x0000000105b901de _tkinter_create_impl + 222
31  _tkinter.cpython-311-darwin.so      0x0000000105b8fe04 _tkinter_create + 164
32  Python                              0x0000000101f941d3 cfunction_vectorcall_FASTCALL + 83
33  Python                              0x000000010205c4cf _PyEval_EvalFrameDefault + 60223
34  Python                              0x0000000102062690 _PyEval_Vector + 128
35  Python                              0x0000000101f2eb76 _PyObject_FastCallDictTstate + 214
36  Python                              0x0000000101fbcbf5 slot_tp_init + 181
37  Python                              0x0000000101fb2d9a type_call + 122
38  Python                              0x0000000101f2e841 _PyObject_MakeTpCall + 129
39  Python                              0x000000010205c5c7 _PyEval_EvalFrameDefault + 60471
40  Python                              0x0000000102062690 _PyEval_Vector + 128
41  Python                              0x0000000101f32c3e method_vectorcall + 334
42  Python                              0x0000000101f2f408 _PyVectorcall_Call + 120
43  Python                              0x000000010205f70a _PyEval_EvalFrameDefault + 73082
44  Python                              0x0000000102062690 _PyEval_Vector + 128
45  Python                              0x0000000101f2f408 _PyVectorcall_Call + 120
46  Python                              0x000000010205f70a _PyEval_EvalFrameDefault + 73082
47  Python                              0x0000000102062690 _PyEval_Vector + 128
48  Python                              0x000000010205f70a _PyEval_EvalFrameDefault + 73082
49  Python                              0x000000010204c64a PyEval_EvalCode + 282
50  Python                              0x00000001020d2818 pyrun_file + 248
51  Python                              0x00000001020d20b4 _PyRun_SimpleFileObject + 292
52  Python                              0x00000001020d168b _PyRun_AnyFileObject + 155
53  Python                              0x00000001020fa27a pymain_run_file_obj + 234
54  Python                              0x00000001020f9b65 pymain_run_file + 85
55  Python                              0x00000001020f9460 Py_RunMain + 2272
56  Python                              0x00000001020fa3eb pymain_main + 43
57  Python                              0x00000001020faf0a Py_BytesMain + 42
58  dyld                                0x00007ff80b900310 start + 2432

@jklymak
Copy link
Member

jklymak commented Jan 16, 2023

Please try a Hello World using tk or pyqt5:

https://www.geeksforgeeks.org/hello-world-in-tkinter/
https://pythonbasics.org/pyqt-hello-world/

If those have the same errors, this is at a lower level than Matplotlib

@apaksoy
Copy link
Author

apaksoy commented Jan 16, 2023

@jklymak The following programs appear to work fine but I get the unwanted output with either of them. Any further suggestions?

Program 1

from tkinter import *
root=Tk()
a = Label(root, text="Hello, world!")
a.pack()

root.mainloop()

Program 2

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QIcon
from PyQt5.QtCore import pyqtSlot

def window():
   app = QApplication(sys.argv)
   widget = QWidget()

   textLabel = QLabel(widget)
   textLabel.setText("Hello World!")
   textLabel.move(110,85)

   widget.setGeometry(50,50,320,200)
   widget.setWindowTitle("PyQt5 Example")
   widget.show()
   sys.exit(app.exec_())

if __name__ == '__main__':
   window()

@jklymak
Copy link
Member

jklymak commented Jan 16, 2023

This means you cannot make any python GUIs show without this output, which means you have an install or library problem that we cannot help with. I would reinstall a fresh environment using conda, and get rid of the corrupt ones. I would not use the native python, nor one downloaded separately from conda. Finally, I should have specified above that I use the conda-forge channel for your conda: conda create -c condo-forge -n boo matplotlib numpy python=3.11

I'm going to close this, as this is not a Matplotlib bug. Feel free to follow up at https://discourse.matplotlib.org for more help on installation issues.

@jklymak jklymak closed this as not planned Won't fix, can't repro, duplicate, stale Jan 16, 2023
@nikohansen
Copy link

nikohansen commented Jan 16, 2023

On 13.1, I cannot replicate with

conda create -n boo matplotlib numpy python=3.11
conda activate boo
python -c "import matplotlib.pyplot as plt; fig, ax = plt.subplots(); ax.plot(range(10)); plt.show()"

This is python 3.11.0, because that is what conda offers.

I can replicate the problem with the exact above commands under macOS 13.1 and M1 Max processor getting:

1   HIToolbox                           0x000000019c9945c8 _ZN15MenuBarInstance22EnsureAutoShowObserverEv + 120
2   HIToolbox                           0x000000019c994188 _ZN15MenuBarInstance14EnableAutoShowEv + 60
3   HIToolbox                           0x000000019c937310 SetMenuBarObscured + 372
4   HIToolbox                           0x000000019c936ee8 _ZN13HIApplication15HandleActivatedEP14OpaqueEventRefhP15OpaqueWindowPtrh + 172
5   HIToolbox                           0x000000019c930fcc _ZN13HIApplication13EventObserverEjP14OpaqueEventRefPv + 296
6   HIToolbox                           0x000000019c8f7cd0 _NotifyEventLoopObservers + 176
7   HIToolbox                           0x000000019c93096c AcquireEventFromQueue + 432
8   HIToolbox                           0x000000019c91fc84 ReceiveNextEventCommon + 320
9   HIToolbox                           0x000000019c91fb2c _BlockUntilNextEventMatchingListInModeWithFilter + 72
10  AppKit                              0x00000001964cc424 _DPSNextEvent + 632
11  AppKit                              0x00000001964cb5b4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728
12  libtk8.6.dylib                      0x0000000115c5be40 TkMacOSXEventsCheckProc + 456
13  libtcl8.6.dylib                     0x0000000115f59a60 Tcl_DoOneEvent + 320
14  libtk8.6.dylib                      0x0000000115c529c0 -[TKApplication(TKInit) applicationDidFinishLaunching:] + 212
15  CoreFoundation                      0x0000000193241570 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 148
16  CoreFoundation                      0x00000001932df054 ___CFXRegistrationPost_block_invoke + 88
17  CoreFoundation                      0x00000001932def9c _CFXRegistrationPost + 440
18  CoreFoundation                      0x0000000193212b74 _CFXNotificationPost + 708
19  Foundation                          0x000000019410072c -[NSNotificationCenter postNotificationName:object:userInfo:] + 88
20  AppKit                              0x00000001964d3810 -[NSApplication _postDidFinishNotification] + 284
21  AppKit                              0x00000001964d35c0 -[NSApplication _sendFinishLaunchingNotification] + 172
22  AppKit                              0x00000001964cc7c8 _DPSNextEvent + 1564
23  AppKit                              0x00000001964cb5b4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 728
24  libtk8.6.dylib                      0x0000000115c5bbe0 TkMacOSXEventsSetupProc + 220
25  libtcl8.6.dylib                     0x0000000115f59a40 Tcl_DoOneEvent + 288
26  libtk8.6.dylib                      0x0000000115c53054 TkpInit + 416
27  libtk8.6.dylib                      0x0000000115bb7ad8 Initialize + 2432
28  _tkinter.cpython-311-darwin.so      0x00000001074fe13c Tkapp_New + 876
29  _tkinter.cpython-311-darwin.so      0x00000001074fdb60 _tkinter_create + 596
30  python3.11                          0x000000010434b090 cfunction_vectorcall_FASTCALL + 256
31  python3.11                          0x00000001042f41cc PyObject_Vectorcall + 76
32  python3.11                          0x00000001043f033c _PyEval_EvalFrameDefault + 46132
33  python3.11                          0x00000001043f48c0 _PyEval_Vector + 184
34  python3.11                          0x00000001042f3a8c _PyObject_FastCallDictTstate + 156
35  python3.11                          0x00000001042f49b4 _PyObject_Call_Prepend + 164
36  python3.11                          0x000000010436e048 slot_tp_init + 196
37  python3.11                          0x00000001043665cc type_call + 372
38  python3.11                          0x00000001042f38c4 _PyObject_MakeTpCall + 332
39  python3.11                          0x00000001043f033c _PyEval_EvalFrameDefault + 46132
40  python3.11                          0x00000001043f48c0 _PyEval_Vector + 184
41  python3.11                          0x00000001042f7374 method_vectorcall + 164
42  python3.11                          0x00000001042f4038 _PyVectorcall_Call + 132
43  python3.11                          0x00000001043f2210 _PyEval_EvalFrameDefault + 54024
44  python3.11                          0x00000001043f48c0 _PyEval_Vector + 184
45  python3.11                          0x00000001042f4038 _PyVectorcall_Call + 132
46  python3.11                          0x00000001043f2210 _PyEval_EvalFrameDefault + 54024
47  python3.11                          0x00000001043f48c0 _PyEval_Vector + 184
48  python3.11                          0x00000001043f2210 _PyEval_EvalFrameDefault + 54024
49  python3.11                          0x00000001043f48c0 _PyEval_Vector + 184
50  python3.11                          0x00000001043f2210 _PyEval_EvalFrameDefault + 54024
51  python3.11                          0x00000001043e3f68 PyEval_EvalCode + 220
52  python3.11                          0x0000000104449a50 run_mod + 144
53  python3.11                          0x000000010444d428 PyRun_SimpleStringFlags + 272
54  python3.11                          0x000000010446ea40 Py_RunMain + 1400
55  python3.11                          0x000000010446ff90 pymain_main + 1332
56  python3.11                          0x000000010429683c main + 56
57  dyld                                0x0000000192e43e50 start + 2544

@greglucas
Copy link
Contributor

Perhaps related to automatically hiding/showing menu bars? Can someone try to change that system setting and seeing if that changes anything? (I'm not able to reproduce either)
https://stackoverflow.com/questions/74609260/r-warnings-errors-in-a-fresh-install

We may need to handle this manually on our side and force the menubar to be hidden/shown? [NSMenu setMenuBarVisible:YES];

@nikohansen
Copy link

Perhaps related to automatically hiding/showing menu bars? Can someone try to change that system setting and seeing if that changes anything?

This workaround does indeed work for me.

@apaksoy
Copy link
Author

apaksoy commented Jan 16, 2023

Originally posted by @greglucas in #24997 (comment)

Perhaps related to automatically hiding/showing menu bars? Can someone try to change that system setting and seeing if that changes anything?

My Mac's (Intel) systems settings under Desktop&Dock->Menu Bar for "Automatically hide and show the menu bar" has been set at Always for a long time. If I change that to Neveror In Full Screen and run the small program in my original post, the unwanted output does not come out while the program continues to work as expected. Same goes for the two "Hello World!" programs I have tried per @jklymak's enquiries.

This helps me isolate the problem but does not solve it because I like to keep the menu bar hidden.

@jklymak Would you still think this is a library or installation problem? Can you also reproduce the problem now? Thx.

@jklymak
Copy link
Member

jklymak commented Jan 16, 2023

If PyQT errors and Tk Errors, then I don't think there is much we can do and this should be reported to those projects. If it is the MacOSX backend, we may be able to do something.

@greglucas
Copy link
Contributor

I think this needs to be fixed upstream actually since it is happening in every backend. I'm not sure what we can do after looking into it a bit.

python/cpython#101067 (comment)

@apaksoy
Copy link
Author

apaksoy commented Jan 25, 2023

Upgraded macOS to 13.2 from 13.1 today. Similar unwanted output continues to come out when the Python code in my original poster is run via the macOS command line interface (the Terminal app) and the aforementioned macOS menu bar setting is at Always or On Desktop Only. As before, the code works fine otherwise and no unwanted output comes out if the menu bar setting is changed, for example, to Never.

@jklymak
Copy link
Member

jklymak commented Jan 25, 2023

It looks like this is a bug on Apple's end. We can't really fix it. Feel free to request a re-open if there is something we can do.

@jklymak jklymak closed this as not planned Won't fix, can't repro, duplicate, stale Jan 25, 2023
@gen740
Copy link

gen740 commented Mar 29, 2023

It seems fixed on Ventura 13.3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants