导入matplotlib.pyplot

时间:2017-10-31 07:14:24

标签: python macos matplotlib

我正在尝试使用matplotlib导入pyplot: import matplotlib.pyplot as plt

我收到以下错误,终止我的python程序。

我的代码最近在我运行El Capitan的旧MacBook Pro 2012上运行。我现在正在使用High Sierra的2017 Macbook Pro上运行...不知道这是否与它有任何关系。我尝试使用pip卸载并重新安装Matplotlib,但仍然遇到同样的问题。我正在使用anaconda安装的Python。感谢帮助!

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

编辑: 当我将Matplotlib的后端更改为'Agg'而不是'TkAgg'时,我没有得到上面的错误,程序运行但数字不显示。

1 个答案:

答案 0 :(得分:3)

我在这篇文章中找到了解决方案(Anaconda Runtime Error: Python is not installed as a framework?

我卸载了matplotlib:pip uninstall matplotlib

然后使用anaconda重新安装它:conda install matplotlib

这似乎解决了所有问题,程序正在运行,就像以前一样。