jupyter / jupyter_console

Jupyter Terminal Console
http://jupyter-console.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
247 stars 146 forks source link

Jupyter console won't work with %matplotlib osx. #294

Closed ubaldot closed 1 year ago

ubaldot commented 1 year ago

Output of %matplotlib osxgive the following error message:

2023-05-03 19:46:24.850 python[46916:7042851] *** Assertion failure in +[NSEvent otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:], NSEvent.m:647
2023-05-03 19:46:24.852 python[46916:7042851] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: _NSEventMask64FromType(type) & WeirdMask'
*** First throw call stack:
(
    0   CoreFoundation                      0x00000001aa69319c __exceptionPreprocess + 176
    1   libobjc.A.dylib                     0x00000001aa1b24d4 objc_exception_throw + 60
    2   Foundation                          0x00000001ab645b88 -[NSCalendarDate initWithCoder:] + 0
    3   AppKit                              0x00000001ad9dad50 +[NSEvent otherEventWithType:location:modifierFlags:timestamp:windowNumber:context:subtype:data1:data2:] + 264
    4   libffi.8.dylib                      0x0000000105ac404c ffi_call_SYSV + 76
    5   libffi.8.dylib                      0x0000000105ac1790 ffi_call_int + 1256
    6   _ctypes.cpython-310-darwin.so       0x0000000105aa4a30 _ctypes_callproc + 1324
    7   _ctypes.cpython-310-darwin.so       0x0000000105a9ebf8 PyCFuncPtr_call + 1160
    8   python3.10                          0x0000000104ed2294 _PyObject_MakeTpCall + 612
    9   python3.10                          0x0000000104fc10f0 call_function + 676
    10  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    11  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    12  python3.10                          0x0000000104fc1058 call_function + 524
    13  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    14  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    15  _ctypes.cpython-310-darwin.so       0x0000000105aa2e0c closure_fcn + 644
    16  libffi.8.dylib                      0x0000000105ac1b6c ffi_closure_SYSV_inner + 796
    17  libffi.8.dylib                      0x0000000105ac41d4 ffi_closure_SYSV + 52
    18  CoreFoundation                      0x00000001aa63448c __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 32
    19  CoreFoundation                      0x00000001aa634134 __CFRunLoopDoTimer + 940
    20  CoreFoundation                      0x00000001aa633c8c __CFRunLoopDoTimers + 356
    21  CoreFoundation                      0x00000001aa61941c __CFRunLoopRun + 1852
    22  CoreFoundation                      0x00000001aa61858c CFRunLoopRunSpecific + 612
    23  HIToolbox                           0x00000001b3e4ddf4 RunCurrentEventLoopInMode + 292
    24  HIToolbox                           0x00000001b3e4dc30 ReceiveNextEventCommon + 648
    25  HIToolbox                           0x00000001b3e4d988 _BlockUntilNextEventMatchingListInModeWithFilter + 76
    26  AppKit                              0x00000001ad837f58 _DPSNextEvent + 636
    27  AppKit                              0x00000001ad8370f4 -[NSApplication(NSEvent) _nextEventMatchingEventMask:untilDate:inMode:dequeue:] + 716
    28  AppKit                              0x00000001ad82b558 -[NSApplication run] + 464
    29  libffi.8.dylib                      0x0000000105ac404c ffi_call_SYSV + 76
    30  libffi.8.dylib                      0x0000000105ac1790 ffi_call_int + 1256
    31  _ctypes.cpython-310-darwin.so       0x0000000105aa4a30 _ctypes_callproc + 1324
    32  _ctypes.cpython-310-darwin.so       0x0000000105a9ebf8 PyCFuncPtr_call + 1160
    33  python3.10                          0x0000000104ed2294 _PyObject_MakeTpCall + 612
    34  python3.10                          0x0000000104fc10f0 call_function + 676
    35  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    36  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    37  python3.10                          0x0000000104fc1058 call_function + 524
    38  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    39  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    40  python3.10                          0x0000000104fc1058 call_function + 524
    41  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    42  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    43  python3.10                          0x000000010506ab04 partial_vectorcall + 396
    44  python3.10                          0x0000000104fc1058 call_function + 524
    45  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    46  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    47  python3.10                          0x0000000104ed5aac method_vectorcall + 516
    48  python3.10                          0x0000000104fd9b78 context_run + 348
    49  python3.10                          0x0000000104f258a8 cfunction_vectorcall_FASTCALL_KEYWORDS + 112
    50  python3.10                          0x0000000104fbd160 _PyEval_EvalFrameDefault + 27276
    51  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    52  python3.10                          0x0000000104fc1058 call_function + 524
    53  python3.10                          0x0000000104fbcdc0 _PyEval_EvalFrameDefault + 26348
    54  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    55  python3.10                          0x0000000104fc1058 call_function + 524
    56  python3.10                          0x0000000104fbcdc0 _PyEval_EvalFrameDefault + 26348
    57  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    58  python3.10                          0x0000000104fc1058 call_function + 524
    59  python3.10                          0x0000000104fbcdc0 _PyEval_EvalFrameDefault + 26348
    60  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    61  python3.10                          0x0000000104fc1058 call_function + 524
    62  python3.10                          0x0000000104fbcdc0 _PyEval_EvalFrameDefault + 26348
    63  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    64  python3.10                          0x0000000104fc1058 call_function + 524
    65  python3.10                          0x0000000104fbcdc0 _PyEval_EvalFrameDefault + 26348
    66  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    67  python3.10                          0x0000000104ed594c method_vectorcall + 164
    68  python3.10                          0x0000000104fc1058 call_function + 524
    69  python3.10                          0x0000000104fbcde8 _PyEval_EvalFrameDefault + 26388
    70  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    71  python3.10                          0x0000000104fb5590 PyEval_EvalCode + 120
    72  python3.10                          0x0000000104fb1108 builtin_exec + 836
    73  python3.10                          0x0000000104f259e4 cfunction_vectorcall_FASTCALL + 200
    74  python3.10                          0x0000000104fc1058 call_function + 524
    75  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    76  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    77  python3.10                          0x0000000104fc1058 call_function + 524
    78  python3.10                          0x0000000104fbce58 _PyEval_EvalFrameDefault + 26500
    79  python3.10                          0x0000000104fb5dc8 _PyEval_Vector + 2056
    80  python3.10                          0x0000000105035164 pymain_run_module + 272
    81  python3.10                          0x00000001050347a0 Py_RunMain + 1584
    82  python3.10                          0x0000000105035c50 pymain_main + 1272
    83  python3.10                          0x0000000104e7c00c main + 56
    84  dyld                                0x00000001aa1e3f28 start + 2236
)
libc++abi: terminating due to uncaught exception of type NSException
/Users/ubaldot/opt/miniconda3/envs/myenv/lib/python3.10/site-packages/jupyter_console/ptshell.py:787: UserWarning: The kernel did not respond to an is_complete_request. Setting `use_kernel_is_complete` to False.
  warn('The kernel did not respond to an is_complete_request. '

I tried to run %matplotlib` both in a IPython and a Jupyter console, getting the following outputs:

the consequence is that plots in IPython are interactive whereas plots in Jupyter console are rendered as a simple .png. Example code follows if you want to test:

import matplotlib.pyplot as plt
import matplotlib
x = list(range(1,5))
y = list(map(lambda x: x**2, x))
plt.plot(x,y)

I am running Jupyter console 6.6.3, Python 3.10.8, IPython 8.12.0 with pyqt 5.51.7 installed through conda on Mac Os Ventura.

Carreau commented 1 year ago

There is no reason for this to happen in JupyterConsole and not in notebook. Can you reproduce this with notebook ? It might be an ipykernel issue, but it's starting to be outside of my area of expertise.

ubaldot commented 1 year ago

Tried with both notebook and jupyter-lab. None worked. Below a screenshot from jupyter-lab. Perhaps this issue should be linked to notebook - jupyter-lab issue trackers?

Screenshot 2023-05-26 at 09 23 08
ubaldot commented 1 year ago

There is no reason for this to happen in JupyterConsole and not in notebook. Can you reproduce this with notebook ? It might be an ipykernel issue, but it's starting to be outside of my area of expertise.

I am not sure if ipython or jupyter console --kernel=python3 use the same ipykernel, but if it is, then the problem is in most likely on jupyter side than ipykernel.

I tried to run the example script from a ipython console (no jupyter) and I had no problems. Everything works as expected.

image
Carreau commented 1 year ago

So $ ipython does not use ipykernel, the main big difference between $ ipython and other things is that ipykernel use threads and eventloops which are likely to break eventloop integrations. So if it fails on both console and lab then it is most likely a ipykernel (maybe IPython issue).

Carreau commented 1 year ago

I've opened https://github.com/ipython/ipykernel/issues/1124 upstream. Closing here.