我有一个使用 cgi 与网站交互的程序。当我像脚本一样运行程序时它可以工作,但是,当我尝试将其与网站界面连接时,我在错误日志中收到以下错误:
Traceback (most recent call last):
File "/usr/lib/cgi-bin/revealMessage.py", line 2, in <module>
import tweepy
File "/usr/local/lib/python2.7/dist-packages/tweepy/__init__.py", line 14, in <module>
from tweepy.api import API
File "/usr/local/lib/python2.7/dist-packages/tweepy/api.py", line 12, in <module>
from tweepy.binder import bind_api
File "/usr/local/lib/python2.7/dist-packages/tweepy/binder.py", line 11, in <module>
import requests
ImportError: No module named requests
[Mon Apr 24 01:49:50.997808 2017] [cgid:error] [pid 1593:tid 139798939764480] [client 127.0.0.1:56852] End of script output before headers: revealMessage.py, referer: http://localhost/hidden.html
我知道最后一个错误可能与我在程序中使用标头的方式有关,但我不明白为什么 tweepy 无法导入请求。这是我安装的一个模块。是什么导致了这种情况发生?
使用 PYTHONPATH 作为环境变量后,您可以安装在特定位置:
pip3 install --target=<Your_Module_Path> <Your_Module>
export PYTHONPATH=<Your_Module_Path>
示例:
安装
pip3 install --target=/usr/local/python3/module requests export PYTHONPATH=/usr/local/python3/module
检查
python3 Python 3.9.1 (default, Sep 17 2023, 22:52:11) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import requests >>> exit()