gpt4 book ai didi

python - 在 Anaconda 中运行 matplotlib 时出错

转载 作者:行者123 更新时间:2023-12-02 10:42:53 25 4
gpt4 key购买 nike

我在 anaconda 环境中运行以下代码:

import matplotlib.pyplot as plt
plt.plot([1,2,3,4])
plt.ylabel('some numbers')
plt.show()

我在 Mac 上的终端中运行代码,我收到以下错误:
    2019-01-20 18:59:25.256 python3[16633:1195559] -[NSApplication _setup:]: unrecognized selector sent to instance 0x7ff7d49ab330
2019-01-20 18:59:25.259 python3[16633:1195559] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[NSApplication _setup:]: unrecognized selector sent to instance 0x7ff7d49ab330'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff37c19ecd __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff63cd1720 objc_exception_throw + 48
2 CoreFoundation 0x00007fff37c97275 -[NSObject(NSObject) __retain_OA] + 0
3 CoreFoundation 0x00007fff37bbbb40 ___forwarding___ + 1486
4 CoreFoundation 0x00007fff37bbb4e8 _CF_forwarding_prep_0 + 120
5 libtk8.6.dylib 0x00000001173f731d TkpInit + 413
6 libtk8.6.dylib 0x000000011734f17e Initialize + 2622
7 _tkinter.cpython-36m-darwin.so 0x0000000117179a46 _tkinter_create + 1174
8 python3 0x000000010b01f958 _PyCFunction_FastCallDict + 200
9 python3 0x000000010b0f6b5f call_function + 143
10 python3 0x000000010b0f4881 _PyEval_EvalFrameDefault + 47217
11 python3 0x000000010b0e7e49 _PyEval_EvalCodeWithName + 425
12 python3 0x000000010b0f772c _PyFunction_FastCallDict + 364
13 python3 0x000000010af9e530 _PyObject_FastCallDict + 320
14 python3 0x000000010afc59a8 method_call + 136
15 python3 0x000000010afa5b8e PyObject_Call + 62
16 python3 0x000000010b046d55 slot_tp_init + 117
17 python3 0x000000010b04b2a1 type_call + 241
18 python3 0x000000010af9e4a1 _PyObject_FastCallDict + 177
19 python3 0x000000010afa66f7 _PyObject_FastCallKeywords + 327
20 python3 0x000000010b0f6c58 call_function + 392
21 python3 0x000000010b0f4931 _PyEval_EvalFrameDefault + 47393
22 python3 0x000000010b0f6f1c fast_function + 188
23 python3 0x000000010b0f6bbc call_function + 236
24 python3 0x000000010b0f4881 _PyEval_EvalFrameDefault + 47217
25 python3 0x000000010b0e7e49 _PyEval_EvalCodeWithName + 425
26 python3 0x000000010b0f772c _PyFunction_FastCallDict + 364
27 python3 0x000000010af9e530 _PyObject_FastCallDict + 320
28 python3 0x000000010afc59a8 method_call + 136
29 python3 0x000000010afa5b8e PyObject_Call + 62
30 python3 0x000000010b0f4a77 _PyEval_EvalFrameDefault + 47719
31 python3 0x000000010b0e7e49 _PyEval_EvalCodeWithName + 425
32 python3 0x000000010b0f6fca fast_function + 362
33 python3 0x000000010b0f6bbc call_function + 236
34 python3 0x000000010b0f4881 _PyEval_EvalFrameDefault + 47217
35 python3 0x000000010b0f6f1c fast_function + 188
36 python3 0x000000010b0f6bbc call_function + 236
37 python3 0x000000010b0f4881 _PyEval_EvalFrameDefault + 47217
38 python3 0x000000010b0e7e49 _PyEval_EvalCodeWithName + 425
39 python3 0x000000010b0f6fca fast_function + 362
40 python3 0x000000010b0f6bbc call_function + 236
41 python3 0x000000010b0f4881 _PyEval_EvalFrameDefault + 47217
42 python3 0x000000010b0e7e49 _PyEval_EvalCodeWithName + 425
43 python3 0x000000010b0f6fca fast_function + 362
44 python3 0x000000010b0f6bbc call_function + 236
45 python3 0x000000010b0f4881 _PyEval_EvalFrameDefault + 47217
46 python3 0x000000010b0e7e49 _PyEval_EvalCodeWithName + 425
47 python3 0x000000010b14040c PyRun_FileExFlags + 252
48 python3 0x000000010b13fb6e PyRun_SimpleFileExFlags + 366
49 python3 0x000000010b1665b6 Py_Main + 3766
50 python3 0x000000010af965c9 main + 313
51 libdyld.dylib 0x00007fff64d9fed9 start + 1
52 ??? 0x0000000000000002 0x0 + 2
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Abort trap: 6

出于某种原因,当我不在 Anaconda 中时,我没有收到错误消息,但我想使用该环境,因为我的程序的其他部分需要其他几个具有依赖关系的包。我该如何解决这个错误?

最佳答案

快速回答是:conda install python.app并使用 pythonw命令而不是 python
在 macOS 中,存在两种不同类型的 Python 构建:常规构建和框架构建。为了通过 native GUI 框架与 macOS 正确交互,您需要一个 Python 框架构建。 (https://matplotlib.org/faq/osx_framework.html)

关于python - 在 Anaconda 中运行 matplotlib 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54282402/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com