6

I'm using matplotlib in a Django app served through apache on Mac OS X 10.7.5 but I can't get it to plot a figure for me. I've imported import matplotlib.pyplot as plt, and the line in my view,

plt.plot(x, y)

(x and y are numpy arrays) is causing the error

2013-01-23 16:39:16.731 httpd[381:203] The application with bundle ID (null) is running setugid(), which is not allowed.

in my apache error_log. I'm afraid I don't know what setugid() is, or how to make running it allowed for my app. My $MPLCONFIGDIR is set to /tmp/.mplconfig and apache as user _www has written a couple of empty directories to it, so that seems to be working OK. Can anyone give me a clue?

Update: if I

from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
from matplotlib.figure import Figure

and set up a figure, subplot and axes (the whole caboodle), I can savefig() without an error... what extra permissions does pyplot need?

3
  • More info here. Seems like a security setting on OS X is preventing it, and the quick fix seems to be to run apache as root. Commented Jan 23, 2013 at 17:13
  • Thanks for the reply tiago. Is running apache as root entirely wise, though? Commented Jan 23, 2013 at 17:19
  • In Linux/Unix apache usually is started as root but runs as user 'nobody'. I don't know in your particular case if it's wise or not. Commented Jan 24, 2013 at 9:53

2 Answers 2

3

Using the agg backend after importing matplotlib got rid of the setugid() error in a Flask app running under OS X Server in Sierra

import matplotlib as mpl

mpl.use('agg')
Sign up to request clarification or add additional context in comments.

Comments

0

You can also add backend configuration globally for your system in ~/.matplotlib/matplotlibrc like:

backend: TkAgg

This will solve your problem as well. If you don't have matplotlibrc, just create one.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.