问题
I'm having some dramas with matplotlib and CGI, despite a night spent searching for solutions.
In brief, I'm running Python2.7 with matplotlib through a Bluhost server. I have want a simple script to display an image, but it's getting stuck on the import of matplotlib:
import cgitb, os
cgitb.enable()
import matplotlib
The traceback yields the following:
: No module named matplotlib args = ('No module named matplotlib',) message = 'No module named matplotlib'
Any clues? It seems most of the matplotlib/cgi issues pertain to specification of a writable HOME folder, yet inserting the following doesn't achieve anything:
os.environ[ 'HOME' ] = '/tmp/'
Any ideas or suggestions would be very welcome!
Cheers, Hugh
回答1:
OK, so it seems the problem has been solved. There were two issues: 1) The paths to the packages weren't properly specified in the PYTHONPATH belonging to the CGI-version of Python, and 2) The CGI ran a different version of python(p2.6), hence there were some incompatibilities with the various packages. I used "python2.6" when installing the numpy & matplotlib modules to ensure they were compatible with p2.6, then temporarily add a link to the package location when I call my script using CGI. Not ideal, but good enough for starters. Thanks for your help!
来源:https://stackoverflow.com/questions/19351309/importing-running-matplotlib-via-cgi