apache 导入错误:存在请求时,没有模块命名的请求

nkhmeac6  于 2023-10-23  发布在  Apache
关注(0)|答案(1)|浏览(115)

我有一个程序,使用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

我知道最后一个错误可能与我在程序中如何使用头有关,但我不明白为什么tweetkey不能导入请求。这是我安装的模块。是什么导致了这一切?

jutyujz0

jutyujz01#

您可以在使用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()

相关问题