【发布时间】:2014-11-14 16:35:43
【问题描述】:
当我在 Django 应用程序中使用 Matplotlib 时遇到segmentation fault: 11。
我用:
python 2.7.8
matplotlib 1.4.2
OS X 10.9.5 (Mavericks)
我看到很多人举报这个segfault 11:
在另一个操作系统上:Segmentation fault in Django with matplotlib,没有答案。
使用另一个包:Segfault 11 with pandas with Python v2.7.6 RC1 on Mac OS X 10.9
使用 Python 3.3.2:Python segfault with OS X 10.9 Mavericks
问题:
segfault: 11 在我尝试访问使用 matplotlib 的 view.py 时出现:
def cht(request):
operations = Comptes.objects.all()
ha = [0]
he = [0]
for i in operations:
if i.commun==True and i.qui=='hadrien':
ha.append(i.montant)
if i.commun==True and i.qui=='helene':
he.append(i.montant)
x = range(0, 2)
y = (sum(ha), sum(he))
# the width of the bars
width = 0.20
# Call the figure and set its size
f = plt.figure(figsize=(300,300))
# Choose the size of the graph in the figure
ax = f.add_axes([0.1, 0.1, 0.8, 0.8])
# Plot the variables
ax.bar(x, y, width, align='center', facecolor='green')
plt.xlabel('Commun')
plt.ylabel('Montant')
plt.xticks(x)
ax.set_xticklabels(['Aye', 'Bee'])
plt.grid(True)
canvas = FigureCanvasAgg(f)
response = HttpResponse(content_type='image/png')
canvas.print_png(response)
plt.close(f)
return response
这是终端中的错误消息:
Django version 1.7.1, using settings 'bud.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.
Segmentation fault: 11
我的尝试:
按照建议,我升级了我的 python 版本,现在我有了python 2.7.8,但问题仍然存在。
我也没有成功地尝试按照该线程的第二个答案的建议对错误应用补丁:Segmentation fault: 11 in OS X。
编辑:
我在 django 之外也遇到了同样的问题:
import matplotlib.pyplot as plt
from matplotlib.backends.backend_agg import FigureCanvasAgg
x = range(0, 2)
y = (50, 20)
width = 0.20
f = plt.figure(figsize=(300,300))
canvas = FigureCanvasAgg(f)
canvas.draw()
它给了我同样的Segmentation fault: 11。
【问题讨论】:
-
我目前面临同样的问题。您设法以某种方式解决了吗?
-
不,我考虑使用 Matplotlib 以外的其他东西(例如,javascript 中的 flot...)
-
嗯,matplotlib 太强大了。如果你做一些科学工作,那么恕我直言,你很难在 javascript 世界中找到替代品。
-
当然!我完全同意。我会尽快安装 Yosemite,希望能解决这个问题。
-
你能在 django 之外重现 segfault 吗?
标签: python django macos matplotlib segmentation-fault