我已经在python3.6中安装了tensorflow_hub包。在python控制台中测试包时,可以正确导入包。但是,当我在cgi脚本中使用它时,会发生一个错误:
no module named tensorflow_hub 源代码
#!/usr/bin/python3.6
import sys
import cgitb
import cgi
t = ''
try:
import tensorflow_hub as tf
except Exception as e:
t = str(e)
cgitb.enable()
sys.stdout.write("Content-Type: application/json")
sys.stdout.write("\n")
sys.stdout.write("\n")
result = dict()
result['data'] = t
sys.stdout.write(json.dumps(result,indent=1))
sys.stdout.write("\n")你能解释一下是哪个问题吗?我测试了其他软件包(例如tensorflow),但我没有任何问题。
编辑
若要安装软件包,请执行以下操作:
pip3 install tensorflow-hub
which pip3
/usr/bin/pip3发布于 2019-05-30 09:41:30
回答我的问题,向有类似问题的人提供反馈:
tensorflow_hub位于~/..local/lib/python3.6/site-packages/其中cgi无法访问。
要找到地点:
pip3 show tensorflow_hub 我注意到在/usr/local/lib/python3.6/dist- packages /
所以,我把包裹从第一个位置移到第二个位置。
这对我有帮助:Why can't python find some modules when I'm running CGI scripts from the web?
https://stackoverflow.com/questions/56365643
复制相似问题