0

I've got a digitalocean droplet and I deployed web2py using this script. I installed matplotlib as follows:

ssh root@ipdroplet
apt-get install python-matplotlib

and I can indeed import matplotlib if I simply run python on the command line after I've ssh'd. The problem is that when I run my app I get the following error:

<type 'exceptions.ImportError'> Cannot import module applications.app.modules.matplotlib

I'm guessing this has something to do with user www-data vs root but no idea how to resolve it. Any help much appreciated. The tips that are mentioned in this link unfortunately didn't help me.

Thanks

EDIT

I should also mention that I'm not using the binary version of web2py. I've also managed to run python as www-data by doing sudo -u www-data python and I can import matplotlib there just fine.

EDIT2

When I was running locally on web2py 2.11.2-stable it worked fine. On my server though I was under 2.12.3-stable. I'm guessing this is probably the reason.

evan54
  • 3,585
  • 5
  • 34
  • 61

1 Answers1

0

So I figured out a solution.

Since it wants to find the matplotlib module in the web2py application's module folder I created a symbolic link from there to the actual installation. I then needed to also change the backend as the little trick didn't work.

ln -s modules/matplotlib path_to_matplotlib

The way I got path_to_matplotlib was:

~#: python
>>> import matplotlib
>>> matplotlib
<module 'matplotlib' from '/usr/lib/pymodules/python2.7/matplotlib>/__init__.pyc
>>> print matplotlib.matplotlib_fname() # This will give the path to the backend settings
/etc/matplotlibrc

so the link command looks like:

ln -s /home/www-data/web2py/applications/app/modules/matplotlib /usr/lib/pymodules/python2.7/matplotlib

I also needed to change the backend, you get the path as shown above ( matplotlib_fname() ). Find the line where it says backend and make sure it is set to Agg.

backend: Agg

usually it's set to TkAgg.

evan54
  • 3,585
  • 5
  • 34
  • 61
  • You should report this on the Google Group. Although web2py will first look in the application's "modules" folder, it certainly does not require that all modules be found there -- if not found, it will search the rest of `sys.path`. – Anthony Sep 07 '15 at 14:30
  • Hm... I've tried in the past posting on the Google group but have failed miserably. If you think it would be useful feel free to post a link to this question and answer. I'll try posting to Google groups but have very low expectations of it working – evan54 Sep 07 '15 at 17:49