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
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
segfault: 11 comes when I try to access the
view.py in which matplotlib is used:
def cht(request): operations = Comptes.objects.all() ha =  he =  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
Here is the error message in the terminal :
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
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) canvas.draw()
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 manage.py runserver --nothreading
Hope, it will help you.