【问题标题】:Segmentation fault: 11 with Matplotlib python 2.7.8 and Mavericks分段错误:11 使用 Matplotlib python 2.7.8 和 Mavericks
【发布时间】: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


【解决方案1】:

我想,我找到了解决办法。至少现在在我自己的应用程序中,我不再有段错误了。所以,解决办法就是这样启动Django服务器:

python manage.py runserver --nothreading

希望对你有帮助。

【讨论】:

  • 并且使用 nothreading 破坏了使用 django 作为服务器的部分意义。
【解决方案2】:

我遇到了类似的“分段错误 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 月)

然后我使用 brew install mercurial 重新安装了 mercurial,这似乎已经解决了导致此问题的任何依赖项。我希望我能更好地理解 Seg 故障发生的情况,但无法深入了解它。

所以,我的建议是使用 brew 更新 python 安装,然后重新安装您依赖的任何其他包。

【讨论】:

  • 谢谢,但实际上答案在 cmets... 我会作为答案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-02-04
  • 2013-11-13
  • 2013-09-17
相关资源
最近更新 更多