Web2Py cannot import module matplotlib

282 views
Skip to first unread message

K. Antonis Tzorvas

unread,
Jul 19, 2013, 9:45:28 PM7/19/13
to web...@googlegroups.com
I've used this script https://github.com/web2py/web2py/blob/master/scripts/setup-web2py-nginx-uwsgi-ubuntu.sh

and the problem is that i cannot import matplotlib in web2py (although it did import numpy)
if i try to run /home/www-data/web2py/web2py.py on another port then there is no problem with the import and the application is running fine

any idea?
thanks

Massimo Di Pierro

unread,
Jul 20, 2013, 3:42:12 AM7/20/13
to web...@googlegroups.com
Look into this. When you import matplotlib it attempts to read(write?) into the MPLCONFIGDIR. If it does not exist for the user or the user (www-data) does not have read/write permission it fails.

K. Antonis Tzorvas

unread,
Jul 20, 2013, 4:53:36 AM7/20/13
to web...@googlegroups.com
I solved this problem by adding
import os
import tempfile
os
.environ['MPLCONFIGDIR'] = tempfile.mkdtemp()

before the import matplotlib and it's running, but i had problems with the plotting due to headless environment i was getting this error from py-Tk:

"no display name and $DISPLAY environment variable"

I Solved this by adding
import matplotlib
matplotlib
.use('Agg')
import matplotlib.pyplot as plt

I've seen your scripts for setting up web2py in such a different ways (with or without redmine/postgresql etc) and i liked this logic, i will go and setup a standard development environment in my remote machine/server so to avoid conflicts when uploading the application in a different environment -- if there is any suggestion, it would be more than pleasantly to hear it!

thanks for your great work!

K. Antonis Tzorvas

unread,
Jul 20, 2013, 11:52:04 AM7/20/13
to web...@googlegroups.com
all operations are noticeably very slow, I haven't changed anything from the setup, any idea on what to look for?

with the same app on pythonanywhere, everything runs faster
Reply all
Reply to author
Forward
0 new messages