我正在使用Django
和Python
进行一个项目,我试图使用matplotlib
绘制一个简单的图形,我一直得到下面显示的错误。Python
也在那之后崩溃了。
我使用mac
,如果这有帮助。Matplotlib
版本“3.1.0”
我已经尝试使用最简单的图表,但问题仍然存在。
这是我在views.py文件中的代码
import matplotlib.pyplot as plt
import numpy as np
from matplotlib.backends.backend_agg import FigureCanvasAgg
import random
def get_svg(request):
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
fig, ax = plt.subplots()
ax.plot(t, s)
ax.set(xlabel='time (s)', ylabel='voltage (mV)',
title='Sample')
ax.grid()
response = HttpResponse(content_type = 'image/png')
canvas = FigureCanvasAgg(fig)
canvas.print_png(response)
return response
这是我得到的错误消息:
2019-06-28 12:04:14.327 Python[76334:18290303] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
*** First throw call stack:
(
0 CoreFoundation 0x00007fff41da1cf9 __exceptionPreprocess + 256
1 libobjc.A.dylib 0x00007fff6c936a17 objc_exception_throw + 48
2 CoreFoundation 0x00007fff41dbb859 -[NSException raise] + 9
3 AppKit 0x00007fff3f3f1e26 -[NSWindow(NSWindow_Theme) _postWindowNeedsToResetDragMarginsUnlessPostingDisabled] + 317
4 AppKit 0x00007fff3f3ef253 -[NSWindow _initContent:styleMask:backing:defer:contentView:] + 1479
5 AppKit 0x00007fff3f3eec86 -[NSWindow initWithContentRect:styleMask:backing:defer:] + 45
6 _macosx.cpython-37m-darwin.so 0x00000001107cf6b0 -[Window initWithContentRect:styleMask:backing:defer:withManager:] + 80
7 _macosx.cpython-37m-darwin.so 0x00000001107d2bc7 FigureManager_init + 327
8 Python 0x00000001059f7087 wrap_init + 12
9 Python 0x00000001059be7ca wrapperdescr_call + 337
10 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
11 Python 0x0000000105a4de20 call_function + 746
12 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
13 Python 0x00000001059b9068 function_code_fastcall + 112
14 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
15 Python 0x00000001059f6ff5 slot_tp_init + 80
16 Python 0x00000001059f3c98 type_call + 172
17 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
18 Python 0x0000000105a4de20 call_function + 746
19 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
20 Python 0x00000001059b9068 function_code_fastcall + 112
21 Python 0x0000000105a4de27 call_function + 753
22 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
23 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
24 Python 0x00000001059b88c1 _PyFunction_FastCallDict + 441
25 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
26 Python 0x00000001059b8d9b PyObject_Call + 136
27 Python 0x0000000105a46e6d _PyEval_EvalFrameDefault + 7162
28 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
29 Python 0x00000001059b88c1 _PyFunction_FastCallDict + 441
30 Python 0x0000000105a46e6d _PyEval_EvalFrameDefault + 7162
31 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
32 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
33 Python 0x0000000105a4de27 call_function + 753
34 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
35 Python 0x00000001059b9068 function_code_fastcall + 112
36 Python 0x0000000105a46e6d _PyEval_EvalFrameDefault + 7162
37 Python 0x00000001059b9068 function_code_fastcall + 112
38 Python 0x0000000105a4de27 call_function + 753
39 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
40 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
41 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
42 Python 0x0000000105a4de27 call_function + 753
43 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
44 Python 0x00000001059b9068 function_code_fastcall + 112
45 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
46 Python 0x00000001059f65fb slot_tp_call + 71
47 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
48 Python 0x0000000105a4de20 call_function + 746
49 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
50 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
51 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
52 Python 0x0000000105a4de27 call_function + 753
53 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
54 Python 0x00000001059b9068 function_code_fastcall + 112
55 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
56 Python 0x00000001059f65fb slot_tp_call + 71
57 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
58 Python 0x0000000105a4de20 call_function + 746
59 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
60 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
61 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
62 Python 0x0000000105a4de27 call_function + 753
63 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
64 Python 0x00000001059b9068 function_code_fastcall + 112
65 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
66 Python 0x00000001059f65fb slot_tp_call + 71
67 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
68 Python 0x0000000105a4de20 call_function + 746
69 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
70 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
71 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
72 Python 0x0000000105a4de27 call_function + 753
73 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
74 Python 0x00000001059b9068 function_code_fastcall + 112
75 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
76 Python 0x00000001059f65fb slot_tp_call + 71
77 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
78 Python 0x0000000105a4de20 call_function + 746
79 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
80 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
81 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
82 Python 0x0000000105a4de27 call_function + 753
83 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
84 Python 0x00000001059b9068 function_code_fastcall + 112
85 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
86 Python 0x00000001059f65fb slot_tp_call + 71
87 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
88 Python 0x0000000105a4de20 call_function + 746
89 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
90 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
91 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
92 Python 0x0000000105a4de27 call_function + 753
93 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
94 Python 0x00000001059b9068 function_code_fastcall + 112
95 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
96 Python 0x00000001059f65fb slot_tp_call + 71
97 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
98 Python 0x0000000105a4de20 call_function + 746
99 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
100 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
101 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
102 Python 0x0000000105a4de27 call_function + 753
103 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
104 Python 0x00000001059b9068 function_code_fastcall + 112
105 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
106 Python 0x00000001059f65fb slot_tp_call + 71
107 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
108 Python 0x0000000105a4de20 call_function + 746
109 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
110 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
111 Python 0x00000001059b8c53 _PyFunction_FastCallKeywords + 225
112 Python 0x0000000105a4de27 call_function + 753
113 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
114 Python 0x00000001059b9068 function_code_fastcall + 112
115 Python 0x0000000105a4de27 call_function + 753
116 Python 0x0000000105a46b81 _PyEval_EvalFrameDefault + 6414
117 Python 0x00000001059b9068 function_code_fastcall + 112
118 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
119 Python 0x00000001059f65fb slot_tp_call + 71
120 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
121 Python 0x0000000105a4de20 call_function + 746
122 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
123 Python 0x0000000105a4e6d3 _PyEval_EvalCodeWithName + 1867
124 Python 0x00000001059b88c1 _PyFunction_FastCallDict + 441
125 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
126 Python 0x00000001059f65fb slot_tp_call + 71
127 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
128 Python 0x0000000105a4de20 call_function + 746
129 Python 0x0000000105a46c35 _PyEval_EvalFrameDefault + 6594
130 Python 0x00000001059b9068 function_code_fastcall + 112
131 Python 0x0000000105a4de27 call_function + 753
132 Python 0x0000000105a46b81 _PyEval_EvalFrameDefault + 6414
133 Python 0x00000001059b9068 function_code_fastcall + 112
134 Python 0x0000000105a4de27 call_function + 753
135 Python 0x0000000105a46b81 _PyEval_EvalFrameDefault + 6414
136 Python 0x00000001059b9068 function_code_fastcall + 112
137 Python 0x0000000105a4de27 call_function + 753
138 Python 0x0000000105a46b81 _PyEval_EvalFrameDefault + 6414
139 Python 0x00000001059b9068 function_code_fastcall + 112
140 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
141 Python 0x00000001059f6ff5 slot_tp_init + 80
142 Python 0x00000001059f3c98 type_call + 172
143 Python 0x00000001059b8af4 _PyObject_FastCallKeywords + 358
144 Python 0x0000000105a4de20 call_function + 746
145 Python 0x0000000105a46b9a _PyEval_EvalFrameDefault + 6439
146 Python 0x00000001059b9068 function_code_fastcall + 112
147 Python 0x0000000105a4de27 call_function + 753
148 Python 0x0000000105a46b81 _PyEval_EvalFrameDefault + 6414
149 Python 0x00000001059b9068 function_code_fastcall + 112
150 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
151 Python 0x00000001059b8d9b PyObject_Call + 136
152 Python 0x0000000105a46e6d _PyEval_EvalFrameDefault + 7162
153 Python 0x00000001059b9068 function_code_fastcall + 112
154 Python 0x0000000105a4de27 call_function + 753
155 Python 0x0000000105a46b81 _PyEval_EvalFrameDefault + 6414
156 Python 0x00000001059b9068 function_code_fastcall + 112
157 Python 0x0000000105a4de27 call_function + 753
158 Python 0x0000000105a46b81 _PyEval_EvalFrameDefault + 6414
159 Python 0x00000001059b9068 function_code_fastcall + 112
160 Python 0x00000001059b99ed _PyObject_Call_Prepend + 150
161 Python 0x00000001059b8d9b PyObject_Call + 136
162 Python 0x0000000105ab52b6 t_bootstrap + 71
163 Python 0x0000000105a7bcd8 pythread_wrapper + 25
164 libsystem_pthread.dylib 0x00007fff6e3522eb _pthread_body + 126
165 libsystem_pthread.dylib 0x00007fff6e355249 _pthread_start + 66
166 libsystem_pthread.dylib 0x00007fff6e35140d thread_start + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
1条答案
按热度按时间2skhul331#
我在Mac上遇到了同样的问题。修复它就像指定“Agg”后端一样简单。
例如: