Segmentation fault: 11 with Matplotlib python 2.7.8 and Mavericks


I encounter a segmentation fault: 11 when I use Matplotlib in an Django app.

I use :

python 2.7.8
matplotlib 1.4.2
OS X 10.9.5 (Mavericks)

I have seen that many people report this segfault 11:

On another OS: Segmentation fault in Django with matplotlib, without answer.

With another package: Segfault 11 with pandas with Python v2.7.6 RC1 on Mac OS X 10.9

With Python 3.3.2: Python segfault with OS X 10.9 Mavericks

The problem:

The segfault: 11 comes when I try to access the in which matplotlib is used:

def cht(request):

    operations = Comptes.objects.all()
    ha = [0]
    he = [0]
    for i in operations:
        if i.commun==True and i.qui=='hadrien':
        if i.commun==True and i.qui=='helene':

    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, y, width, align='center', facecolor='green')
    ax.set_xticklabels(['Aye', 'Bee'])

    canvas = FigureCanvasAgg(f)
    response = HttpResponse(content_type='image/png')

    return response

Here is the error message in the terminal :

Django version 1.7.1, using settings 'bud.settings'
Starting development server at
Quit the server with CONTROL-C.
Segmentation fault: 11

What I've tried :

As recommended I upgraded my version of python and I have now python 2.7.8 but the problem remains.

I also unsuccessfully tried to apply a patch to the bug as recommended by the second answer of this thread : Segmentation fault: 11 in OS X.


I'm having the same problem outside of django with this code:

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)

It gives me the same Segmentation fault: 11.

I guess, I have found a solution. At least now in my own app I do not have segfault anymore. So, the solution is to start Django server in this way:

python runserver --nothreading

Hope, it will help you.