本文介绍了当我从网上运行CGI脚本时,为什么python无法找到某些模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我不知道这里可能是什么问题
I have no idea what could be the problem here:
我有一些来自Biopython的模块,当使用交互式提示或通过命令行执行python脚本时,可以轻松导入这些模块.
I have some modules from Biopython which I can import easily when using the interactive prompt or executing python scripts via the command-line.
问题是,当我尝试在可通过网络执行的cgi脚本中导入相同的biopython模块时,出现导入错误"
The problem is, when I try and import the same biopython modules in a web-executable cgi script, I get a "Import Error"
这里有什么想法吗?
推荐答案
有以下两种可能性:
- Apache(在Unix上)通常以不同的用户身份和不同的环境运行,以从命令行运行python.尝试制作一个仅打印
sys.version
和sys.prefix
的小脚本,并通过apache和通过命令行比较结果,以确保您在两种环境中都使用相同的python安装. - Biopython是否安装在您的主目录下,或者仅对普通用户可读?同样,由于apache通常以其他用户身份运行,因此也许您无权访问该位置,因此无法导入它.
- 您可以在尝试导入Biopython之前尝试执行
import site
吗?可能是某些原因阻止了您通过apache运行时导入网站程序包.
- Apache (on Unix) generally runs as a different user, and with a different environment, to python from the command line. Try making a small script that just prints out
sys.version
andsys.prefix
, and compare the result through apache and via the command line, to make sure that you're running from the same installation of python in both environments. - Is Biopython installed under your home directory, or only readable just for your normal user? Again, because apache generally runs as a different user, perhaps you don't have access to that location, so can't import it.
- Can you try doing
import site
before trying to import Biopython? Perhaps something is preventing site packages from being imported when you run through apache.
这篇关于当我从网上运行CGI脚本时,为什么python无法找到某些模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!