简体   繁体   中英

Python ImportError: No module named requests when requirements are already satisfied

I am using Linux server envirnoment and trying to execute simple python script.

#!/usr/bin/env python

import os
import requests

After execution i get this error:

File "./tele.py", line 4, in <module>
    import requests
ImportError: No module named requests

I tried all possible options and also searched earlier threads to resolve the issue but sadly nothing worked so far

Options I tried:

Install virtual environment and tried pip install request.

pip install requests

Also, tried uninstalling global request library and install only in virtual env.

It is also getting installed and also giving me message as below:

  Downloading requests-2.25.1-py2.py3-none-any.whl (61 kB)
     |################################| 61 kB 31.3 MB/s
Requirement already satisfied: chardet<5,>=3.0.2 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (4.0.0)
Requirement already satisfied: idna<3,>=2.5 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (2.10)
Requirement already satisfied: certifi>=2017.4.17 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (2020.12.5)
Requirement already satisfied: urllib3<1.27,>=1.21.1 in /home/tguser/.local/lib/python3.6/site-packages (from requests) (1.26.2)
Installing collected packages: requests
Successfully installed requests-2.25.1

Also, tried to add python3 forcefully in my script but that is also not working

One more option tried:

import urllib3.requests

pip list is showing the module request,

requests              2.25.1
requests-oauthlib     1.3.0
requests-toolbelt     0.8.0
requests-unixsocket   0.1.5

My python versions are:

Python -V -> Python 2.7.17
Python3 -V -> Python 3.6.9
pip -V -> pip 21.0 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)
pip3 -V -> pip 21.0 from /usr/local/lib/python3.6/dist-packages/pip (python 3.6)

Can anyone help me to resolve the issue?

-PD

Thanks. The issues was resolved using installation.

 sudo apt-get install python-requests --upgrade

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM