2

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.

4
  • 1
    Maybe stackoverflow.com/questions/32078005/… can help you? Commented Oct 31, 2017 at 7:17
  • Does it work with a different backend? import matplotlib; matplotlib.use('Agg'); import matplotlib.pyplot as plt? Commented Oct 31, 2017 at 7:50
  • @jonnybazookatone that seemed to fix the error that causes the program to crash but now my figure/plot isn't being displayed Commented Oct 31, 2017 at 15:26
  • Your problem was not having the backend you were using installed correctly (TkAgg), or the correct version. Your solution of uninstall/install alleviated this. @Thomas gave the correct hint. matplotlib.org/faq/usage_faq.html#what-is-a-backend Commented Nov 2, 2017 at 9:13

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.