分段错误:11与Matplotlib python 2.7.8和小牛队

时间:2014-11-14 16:35:44

标签: python django macos matplotlib segmentation-fault

当我在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

问题:

当我尝试访问使用matplotlib的segfault: 11时出现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

2 个答案:

答案 0 :(得分:2)

我想,我找到了解决方案。至少现在在我自己的应用程序中,我不再有段错误了。因此,解决方案是以这种方式启动Django服务器:

python manage.py runserver --nothreading

希望,它会对你有帮助。

答案 1 :(得分:1)

我遇到了类似的分段故障11'错误,但对我来说,它使用mercurial(hg)

这是尝试使用安装程序安装的Python 2.7.8和pip install mercurial 在OS X 10.9.5上

起初我以为它与readline.so错误有关,并尝试重命名(以避免加载)虽然我发现很难理解如果它被调用会有什么帮助。然后找到了关于此的以下主题。

Segmentation fault: 11 in OS X

最后,我的解决方案似乎来自于使用homebrew安装python,然后使用它安装python以获得2.7.8版本(截至2014年12月)

然后我重新安装了mercurial与brew install mercurial,它似乎解决了造成这种情况的依赖关系。我希望我能更好地理解Seg故障发生的情况,但无法深入了解它。

所以,我建议用brew更新python安装,然后重新安装你依赖的其他软件包。