汇入与汇入通过CGI运行matplotlib [英] Importing & running matplotlib via CGI

查看:67
本文介绍了汇入与汇入通过CGI运行matplotlib的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

尽管花了一整夜寻找解决方案,但我还是和matplotlib和CGI一起玩电视剧.

I'm having some dramas with matplotlib and CGI, despite a night spent searching for solutions.

简而言之,我正在通过Bluhost服务器使用matplotlib运行Python2.7.我想要一个简单的脚本来显示图像,但是它被卡在matplotlib的导入上:

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

回溯会产生以下内容:

:没有名为matplotlib的模块args =('没有名为matplotlib的模块',)message ='没有名为matplotlib的模块'

: No module named matplotlib args = ('No module named matplotlib',) message = 'No module named matplotlib'

有任何线索吗?似乎大多数matplotlib/cgi问题都与可写HOME文件夹的规范有关,但是插入以下内容并没有实现任何目的:

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!

干杯,休

推荐答案

好,看来问题已经解决了.存在两个问题:1)在属于CGI版本的Python的PYTHONPATH中未正确指定软件包的路径,以及2)CGI运行了不同版本的python(p2.6),因此存在一些问题与各种软件包不兼容.我在安装numpy&时使用了"python2.6"matplotlib模块以确保它们与p2.6兼容,然后在我使用CGI调用脚本时临时添加指向软件包位置的链接.不理想,但对于初学者来说足够好.谢谢你的帮助!

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!

这篇关于汇入与汇入通过CGI运行matplotlib的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆