当我在Django应用程序中使用Matplotlib时,我遇到了一个segmentation fault: 11
。
我使用 :
python 2.7.8
matplotlib 1.4.2
OS X 10.9.5 (Mavericks)
我看到很多人举报这个segfault 11
:
在另一个操作系统上:Django 中使用 matplotlib 的分段错误,没有答案。
使用另一个软件包:Segfault 11 with pandas with Python v2.7.6 RC1 on Mac OS X 10.9
使用 Python 3.3.2:OS X 10.9 Mavericks 的 Python 段错误
问题:
当我尝试访问使用 matplotlib 的view.py
时,会出现segfault: 11
:
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
了,但问题仍然存在。
我也尝试按照该线程的第二个答案的建议对该错误应用补丁,但没有成功:分段错误:OS X 中的 11。
编辑:
我在 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
.
,我已经找到了解决方案。至少现在在我自己的应用程序中,我不再有段错误了。所以,解决方案是以这种方式启动 Django 服务器:
python manage.py runserver --nothreading
希望它能帮助你。
我遇到了类似的"分段错误 11"错误,但对我来说,它使用的是 mercurial(hg)
这是尝试使用通过安装程序和pip安装mercurial安装的Python 2.7.8在 OS X 10.9.5 上
起初我认为它与 readline.so 错误有关,并尝试重命名它(以避免加载),尽管我发现很难理解如果调用它会有什么帮助。 然后找到了以下有关此的线程。
分段错误:OS X 中为 11
最后,我的解决方案似乎来自使用自制软件安装python,然后使用它安装python以获得2.7.8版本(截至2014年12月)
然后,我重新安装了 mercurial 和brew install mercurial,这似乎已经解决了导致此问题的任何依赖项。 我希望我能更好地理解赛格故障发生了什么,但无法深入了解它。
因此,我的建议是使用 brew 更新 python 安装,然后重新安装您依赖的任何其他软件包。