Solved: ModuleNotFoundError: No module named ‘requests’ in Python 3

Are you trying to run python program and getting "ModuleNotFoundError: No module named 'requests" error ? Do you want to Know how to solve "ModuleNotFoundError: No module named 'requests'" error ? Do you want to know how to install a Python module on RHEL/CentOS Based Servers ? If you are looking answer for all these queries then you have reached the correct place. In this article, I will show you how to install Python requests module if it is currently missing in your server. You can install this or any other python modules by using 2 different ways. Both ways are explained below with examples.

Solved: ModuleNotFoundError: No module named 'requests' in Python 3

Solved: ModuleNotFoundError: No module named ‘requests’ in Python 3

Also Read: How to Properly Search PHP Modules using YUM tool in Linux(RHEL/CentOS 7/8)

If you are getting "ModuleNotFoundError: No module named 'requests'" error then it means either requests module is not installed or if it is installed then python is not able to find it. If it is not installed then you can easily install by using python3 -m pip install requests command as shown below. Here you can notice that for this command to work you need to have python3 installed in your Server. If you don’t have python3 installed in your Server then you can install it by using yum install python3 -y command. Now if you run the python program again you won’t see "ModuleNotFoundError: No module named 'requests'" error.

[root@localhost ~]# python3 -m pip install requests
WARNING: Running pip install with root privileges is generally not a good idea. Try `__main__.py install --user` instead.
Collecting requests
Downloading https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl (61kB)
100% |████████████████████████████████| 71kB 1.8MB/s
Collecting certifi>=2017.4.17 (from requests)
Downloading https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl (156kB)
100% |████████████████████████████████| 163kB 1.8MB/s
Collecting idna<3,>=2.5 (from requests)
Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)
100% |████████████████████████████████| 61kB 4.7MB/s
Collecting chardet<4,>=3.0.2 (from requests)
Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 4.1MB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
Downloading https://files.pythonhosted.org/packages/56/aa/4ef5aa67a9a62505db124a5cb5262332d1d4153462eb8fd89c9fa41e5d92/urllib3-1.25.11-py2.py3-none-any.whl (127kB)
100% |████████████████████████████████| 133kB 4.7MB/s
Installing collected packages: certifi, idna, chardet, urllib3, requests
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 urllib3-1.25.11

Other way that you can use to install requests module is through pip3.6 tool. You can use simply use pip3.6 install requests command to install requests module in your Server. You don’t require yum tool here. Here you only need to make sure that you have pip3.6 tool available as per the python version that you are going to use. Since here we are using python3 so we need to use pip3.6 to install modules for this version. If you don’t have this pip version installed then you can install it by using yum install python3-pip -y command.

[root@localhost ~]# pip3.6 install requests
WARNING: Running pip install with root privileges is generally not a good idea. Try `pip3.6 install --user` instead.
Collecting requests
Downloading https://files.pythonhosted.org/packages/45/1e/0c169c6a5381e241ba7404532c16a21d86ab872c9bed8bdcd4c423954103/requests-2.24.0-py2.py3-none-any.whl (61kB)
100% |████████████████████████████████| 71kB 2.0MB/s
Collecting certifi>=2017.4.17 (from requests)
Downloading https://files.pythonhosted.org/packages/5e/c4/6c4fe722df5343c33226f0b4e0bb042e4dc13483228b4718baf286f86d87/certifi-2020.6.20-py2.py3-none-any.whl (156kB)
100% |████████████████████████████████| 163kB 1.9MB/s
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests)
Downloading https://files.pythonhosted.org/packages/56/aa/4ef5aa67a9a62505db124a5cb5262332d1d4153462eb8fd89c9fa41e5d92/urllib3-1.25.11-py2.py3-none-any.whl (127kB)
100% |████████████████████████████████| 133kB 4.3MB/s
Collecting chardet<4,>=3.0.2 (from requests)
Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
100% |████████████████████████████████| 143kB 4.2MB/s
Collecting idna<3,>=2.5 (from requests)
Downloading https://files.pythonhosted.org/packages/a2/38/928ddce2273eaa564f6f50de919327bf3a00f091b5baba8dfa9460f3a8a8/idna-2.10-py2.py3-none-any.whl (58kB)
100% |████████████████████████████████| 61kB 5.7MB/s
Installing collected packages: certifi, urllib3, chardet, idna, requests
Successfully installed certifi-2020.6.20 chardet-3.0.4 idna-2.10 requests-2.24.0 urllib3-1.25.11

Similarly, you can install other python modules as well by using pip3.6 install <python_module> command. If you want to uninstall requests module then you can do it by using pip3.6 uninstall requests command as shown below. So you can use pip3.6 tool for installation as well as for uninstallation of python modules. More can be checked on pip Official Documentation.

[root@localhost ~]# pip3.6 uninstall requests
Uninstalling requests-2.24.0:
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/DESCRIPTION.rst
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/INSTALLER
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/LICENSE.txt
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/METADATA
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/RECORD
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/WHEEL
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/metadata.json
/usr/local/lib/python3.6/site-packages/requests-2.24.0.dist-info/top_level.txt
/usr/local/lib/python3.6/site-packages/requests/__init__.py
/usr/local/lib/python3.6/site-packages/requests/__pycache__/__init__.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/__version__.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/_internal_utils.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/adapters.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/api.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/auth.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/certs.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/compat.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/cookies.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/exceptions.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/help.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/hooks.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/models.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/packages.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/sessions.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/status_codes.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/structures.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__pycache__/utils.cpython-36.pyc
/usr/local/lib/python3.6/site-packages/requests/__version__.py
/usr/local/lib/python3.6/site-packages/requests/_internal_utils.py
/usr/local/lib/python3.6/site-packages/requests/adapters.py
/usr/local/lib/python3.6/site-packages/requests/api.py
/usr/local/lib/python3.6/site-packages/requests/auth.py
/usr/local/lib/python3.6/site-packages/requests/certs.py
/usr/local/lib/python3.6/site-packages/requests/compat.py
/usr/local/lib/python3.6/site-packages/requests/cookies.py
/usr/local/lib/python3.6/site-packages/requests/exceptions.py
/usr/local/lib/python3.6/site-packages/requests/help.py
/usr/local/lib/python3.6/site-packages/requests/hooks.py
/usr/local/lib/python3.6/site-packages/requests/models.py
/usr/local/lib/python3.6/site-packages/requests/packages.py
/usr/local/lib/python3.6/site-packages/requests/sessions.py
/usr/local/lib/python3.6/site-packages/requests/status_codes.py
/usr/local/lib/python3.6/site-packages/requests/structures.py
/usr/local/lib/python3.6/site-packages/requests/utils.py
Proceed (y/n)? y
Successfully uninstalled requests-2.24.0

 

 

Popular Recommendations:-

Solved: FATAL: Authentication Helper Program /usr/lib/squid/basic_ncsa_auth: (2) No Such File or Directory

Advertisements

How to Install and Configure Squid Proxy Server on RHEL/CentOS 7/8

Primitive Data Types in Java – int, char, byte, short, long, float, double and boolean

5 Best Ways to Become root user or Superuser in Linux (RHEL/CentOS/Ubuntu)

11 Best Python OS Module Examples on Linux

How to Install MariaDB 5.5 Server on RHEL/CentOS 7 Linux with Easy Steps

6 Simple Steps to Change/Reset MariaDB root password on RHEL/CentOS 7/8

Best Steps to Install Java on RHEL 8/CentOS 8

Advertisements

Leave a Reply