Simon Kalouche
Simon Kalouche

Reputation: 51

Python crashes when importing matplotlib.pyplot

I am trying to import pyplot from matplotlib using: import matplotlib.pyplot as plt

and i receive the following error which terminates my python program.

My code was recently working on my old MacBook Pro 2012 running El Capitan. I am now running on a 2017 Macbook Pro with High Sierra... don't know if this has anything to do with it. I tried uninstalling and reinstalling Matplotlib using pip but still get the same issue. I'm using anaconda installation of Python. Help is appreciated!

2017-10-31 00:05:27.991 python[69256:37459662] -[TKWindow setCanCycle:]: unrecognized selector sent to instance 0x1030d41a0
2017-10-31 00:05:28.000 python[69256:37459662] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[TKWindow setCanCycle:]: unrecognized selector sent to instance 0x1030d41a0'
*** First throw call stack:
(
    0   CoreFoundation                      0x00007fff2aedb0fb __exceptionPreprocess + 171
    1   libobjc.A.dylib                     0x00007fff517c9c76 objc_exception_throw + 48
    2   CoreFoundation                      0x00007fff2af73c34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
    3   CoreFoundation                      0x00007fff2ae51510 ___forwarding___ + 1456
    4   CoreFoundation                      0x00007fff2ae50ed8 _CF_forwarding_prep_0 + 120
    5   libtk8.5.dylib                      0x00000001079eff9f ApplyWindowAttributeFlagChanges + 1124
    6   libtk8.5.dylib                      0x00000001079f0aa8 TkMacOSXApplyWindowAttributes + 51
    7   libtk8.5.dylib                      0x00000001079f0f86 TkMacOSXMakeRealWindowExist + 1189
    8   libtk8.5.dylib                      0x00000001079f112a TkWmMapWindow + 52
    9   libtk8.5.dylib                      0x000000010795a918 Tk_MapWindow + 65
    10  libtk8.5.dylib                      0x0000000107963469 MapFrame + 62
    11  libtcl8.5.dylib                     0x00000001078c0178 TclServiceIdle + 76
    12  libtcl8.5.dylib                     0x00000001078a5491 Tcl_DoOneEvent + 329
    13  _tkinter.so                         0x00000001063ea573 EventHook + 195
    14  gnureadline.so                      0x0000000104deb4ec call_readline + 364
    15  libpython2.7.dylib                  0x0000000100009000 PyOS_Readline + 256
    16  libpython2.7.dylib                  0x00000001000b8b55 builtin_raw_input + 597
    17  libpython2.7.dylib                  0x00000001000c3d7d PyEval_EvalFrameEx + 24989
    18  libpython2.7.dylib                  0x00000001000c6063 PyEval_EvalCodeEx + 2115
    19  libpython2.7.dylib                  0x00000001000c40d0 PyEval_EvalFrameEx + 25840
    20  libpython2.7.dylib                  0x00000001000c6063 PyEval_EvalCodeEx + 2115
    21  libpython2.7.dylib                  0x00000001000c40d0 PyEval_EvalFrameEx + 25840
    22  libpython2.7.dylib                  0x00000001000c6063 PyEval_EvalCodeEx + 2115
    23  libpython2.7.dylib                  0x00000001000c40d0 PyEval_EvalFrameEx + 25840
    24  libpython2.7.dylib                  0x00000001000c6063 PyEval_EvalCodeEx + 2115
    25  libpython2.7.dylib                  0x00000001000c40d0 PyEval_EvalFrameEx + 25840
    26  libpython2.7.dylib                  0x00000001000c6063 PyEval_EvalCodeEx + 2115
    27  libpython2.7.dylib                  0x000000010003e4d0 function_call + 176
    28  libpython2.7.dylib                  0x000000010000cab2 PyObject_Call + 98
    29  libpython2.7.dylib                  0x00000001000bedca PyEval_EvalFrameEx + 4586
    30  libpython2.7.dylib                  0x00000001000c6063 PyEval_EvalCodeEx + 2115
    31  libpython2.7.dylib                  0x00000001000c40d0 PyEval_EvalFrameEx + 25840
    32  libpython2.7.dylib                  0x00000001000c6063 PyEval_EvalCodeEx + 2115
    33  libpython2.7.dylib                  0x00000001000c6186 PyEval_EvalCode + 54
    34  libpython2.7.dylib                  0x00000001000eb43e PyRun_FileExFlags + 174
    35  libpython2.7.dylib                  0x00000001000eb6da PyRun_SimpleFileExFlags + 458
    36  libpython2.7.dylib                  0x000000010010272d Py_Main + 3165
    37  python                              0x0000000100000f54 start + 52
    38  ???                                 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

Edit: When I change the backend of Matplotlib to 'Agg' instead of 'TkAgg' I do not get the error above and the program runs but the figures do not display.

Upvotes: 2

Views: 3036

Answers (1)

Simon Kalouche
Simon Kalouche

Reputation: 51

I found the solution in this post (Anaconda Runtime Error: Python is not installed as a framework?)

I uninstalled matplotlib: pip uninstall matplotlib

and then reinstalled it using anaconda: conda install matplotlib

This seemed to solve all the issues and the program is running as it was before.

Upvotes: 3

Related Questions