Importing & running matplotlib via CGI

别等时光非礼了梦想. 提交于 2021-02-11 17:28:19

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!