ImportError: No module named requests

PythonPython RequestsPython Import

Python Problem Overview


I tried importing requests:

import requests

But I get an error:

> ImportError: No module named requests

Python Solutions


Solution 1 - Python

Requests is not a built in module (does not come with the default python installation), so you will have to install it:

OSX/Linux

Use $ pip install requests (or pip3 install requests for python3) if you have pip installed. If pip is installed but not in your path you can use python -m pip install requests (or python3 -m pip install requests for python3)

Alternatively you can also use sudo easy_install -U requests if you have easy_install installed.

Alternatively you can use your systems package manager:

For centos: yum install python-requests For Ubuntu: apt-get install python-requests

Windows

Use pip install requests (or pip3 install requests for python3) if you have pip installed and Pip.exe added to the Path Environment Variable. If pip is installed but not in your path you can use python -m pip install requests (or python3 -m pip install requests for python3)

Alternatively from a cmd prompt, use > Path\easy_install.exe requests, where Path is your Python*\Scripts folder, if it was installed. (For example: C:\Python32\Scripts)

If you manually want to add a library to a windows machine, you can download the compressed library, uncompress it, and then place it into the Lib\site-packages folder of your python path. (For example: C:\Python27\Lib\site-packages)

From Source (Universal)

For any missing library, the source is usually available at https://pypi.python.org/pypi/. You can download requests here: https://pypi.python.org/pypi/requests

On mac osx and windows, after downloading the source zip, uncompress it and from the termiminal/cmd run python setup.py install from the uncompressed dir.

(source)

Solution 2 - Python

It's not obvious to me which version of Python you are using.

If it's Python 3, a solution would be sudo pip3 install requests

Solution 3 - Python

To install requests module on Debian/Ubuntu for Python2:

$ sudo apt-get install python-requests

And for Python3 the command is:

$ sudo apt-get install python3-requests

Solution 4 - Python

Brew users can use reference below,

command to install requests:

python3 -m pip install requests

Homebrew and Python

pip is the package installer for Python and you need the package requests.

Solution 5 - Python

This may be a liittle bit too late but this command can be run even when pip path is not set. I am using Python 3.7 running on Windows 10 and this is the command

py -m pip install requests

and you can also replace 'requests' with any other uninstalled library

Solution 6 - Python

If you are using Ubuntu, there is need to install requests

run this command:

pip install requests

if you face permission denied error, use sudo before command:

sudo pip install requests

Solution 7 - Python

On OSX, the command will depend on the flavour of python installation you have.

Python 2.x - Default

sudo pip install requests

Python 3.x

sudo pip3 install requests

Solution 8 - Python

In my case requests was already installed, but needed an upgrade. The following command did the trick

$ sudo pip install requests --upgrade

Solution 9 - Python

On Windows Open Command Line

pip3 install requests

Solution 10 - Python

I had the same issue, so I copied the folder named "requests" from https://pypi.python.org/pypi/requests#downloads[requests download]1 to "/Library/Python/2.7/site-packages". Now when you use: import requests, it should work fine.

Solution 11 - Python

In the terminal/command-line:
pip install requests 

then use it inside your Python script by:

import requests
or else if you want to use pycharm IDE to install a package:
  1. go to setting from File in menu
  2. next go to Python interpreter
  3. click on pip
  4. search for requests package and install it

Solution 12 - Python

Adding Third-party Packages to the Application

Follow this link https://cloud.google.com/appengine/docs/python/tools/libraries27?hl=en#vendoring

step1 : Have a file by named a file named appengine_config.py in the root of your project, then add these lines:

from google.appengine.ext import vendor

Add any libraries installed in the "lib" folder.

vendor.add('lib')

Step 2: create a directory and name it "lib" under root directory of project.

step 3: use pip install -t lib requests

step 4 : deploy to app engine.

Solution 13 - Python

Try sudo apt-get install python-requests.

This worked for me.

Solution 14 - Python

The only thing that worked for me:

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
pip install requests

Solution 15 - Python

For windows just give path as cd and path to the "Scripts" of python and then execute the command easy_install.exe requests.Then try import requests...

Solution 16 - Python

If you are using anaconda as your python package manager, execute the following:

conda install -c anaconda requests

Installing requests through pip didn't help me.

Solution 17 - Python

Facing the same issue but unable to fix it with the above solution, so I tried this way and it worked:-

  1. curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py

  2. sudo python2 get-pip.py

  3. python -m pip install requests

Solution 18 - Python

I have had this issue a couple times in the past few months. I haven't seen a good solution for fedora systems posted, so here's yet another solution. I'm using RHEL7, and I discovered the following:

If you have urllib3 installed via pip, and requests installed via yum you will have issues, even if you have the correct packages installed. The same will apply if you have urllib3 installed via yum, and requests installed via pip. Here's what I did to fix the issue:

sudo pip uninstall requests
sudo pip uninstall urllib3
sudo yum remove python-urllib3
sudo yum remove python-requests

(confirm that all those libraries have been removed)

sudo yum install python-urllib3
sudo yum install python-requests

Just be aware that this will only work for systems that are running Fedora, Redhat, or CentOS.

Sources:
This very question (in the comments to this answer).
This github issue.

Solution 19 - Python

Python Common installation issues

These commands are also useful if Homebrew screws up your path on macOS.
python -m pip install requests

or

python3 -m pip install requests

Multiple versions of Python installed in parallel?

Solution 20 - Python

Please try the following. If one doesn't work, skip to the next method.

pip install requests

or...

pip3 install requests

or...

python -m pip install requests

or...

python3 -m pip install requests

or...

python -m pip3 install requests

If all of these don't work, please leave a comment!
How does this work? Depending on the operating system you currently use, the pip command may vary or not work on some. These are the commands you may try in order for a fix.

Solution 21 - Python

I have installed python2.7 and python3.6

Open Command Line to ~/.bash_profile I find that #Setting PATH for Python 3.6 , So I change the path to PATH="/usr/local/Cellar/python/2.7.13/bin:${PATH}" , (please make sure your python2.7's path) ,then save. It works for me.

Solution 22 - Python

if you want request import on windows:

pip install request

then beautifulsoup4 for:

pip3 install beautifulsoup4

Solution 23 - Python

You must make sure your requests module is not being installed in a more recent version of python.

When using python 3.7, run your python file like:

python3 myfile.py

or enter python interactive mode with:

python3

Yes, this works for me. Run your file like this: python3 file.py

Solution 24 - Python

I solved this problem.You can try this method. In this file '.bash_profile', Add codes like alias python=/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7

Solution 25 - Python

You get an import error because requests are not a built-in module instead, it is created by someone else and you need to install the requests.

use the following command on your terminal then it will work correctly.

pip install requests

Install python requests library and this error will be solved.

Solution 26 - Python

My answer is basically the same as @pi-k. In my case my program worked locally but failed to build on QA servers. (I suspect devops had older versions of the package blocked and my version must have been too out-of-date) I just decided to upgrade everything

$ pip install pip-review
$ pip-review --local --interactive

Solution 27 - Python

If you are using anaconda step 1: where python step 2: open anaconda prompt in administrator mode step 3: cd <python path> step 4: install the package in this location

Solution 28 - Python

In my case it was showing request Requirement already satisfied . so I use.

sudo pip3 install requests

Solution 29 - Python

I had the same error even though I installed 'requests' several times. The problem was that I was installing requests in the global Python environment and not in the app virtual environment. Once I installed requests in the Virtual environment, the error disappeared. So here is a good reading on how to install 'requests' in the app virtual environment: Virtual Environments and Packages

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionuser2476540View Question on Stackoverflow
Solution 1 - PythonTheoretiCALView Answer on Stackoverflow
Solution 2 - PythonSamPutnamView Answer on Stackoverflow
Solution 3 - PythonDemingView Answer on Stackoverflow
Solution 4 - PythonymutluView Answer on Stackoverflow
Solution 5 - Pythondee cueView Answer on Stackoverflow
Solution 6 - PythonAwaisView Answer on Stackoverflow
Solution 7 - PythoniosCuratorView Answer on Stackoverflow
Solution 8 - PythonbobbydevView Answer on Stackoverflow
Solution 9 - Pythonsaigopi.meView Answer on Stackoverflow
Solution 10 - Pythonbigboss21View Answer on Stackoverflow
Solution 11 - PythonmamalView Answer on Stackoverflow
Solution 12 - Pythonkrishna kanthView Answer on Stackoverflow
Solution 13 - PythonSarvagya GuptaView Answer on Stackoverflow
Solution 14 - PythonJoviano DiasView Answer on Stackoverflow
Solution 15 - PythonjazzView Answer on Stackoverflow
Solution 16 - PythonArnab BiswasView Answer on Stackoverflow
Solution 17 - PythonKumar Pankaj DubeyView Answer on Stackoverflow
Solution 18 - PythonajsmartView Answer on Stackoverflow
Solution 19 - PythonRandyMcMillanView Answer on Stackoverflow
Solution 20 - PythonHeewoonView Answer on Stackoverflow
Solution 21 - Python朽木自雕View Answer on Stackoverflow
Solution 22 - PythonSefa AYDINView Answer on Stackoverflow
Solution 23 - PythonAndreas BiggerView Answer on Stackoverflow
Solution 24 - PythongusView Answer on Stackoverflow
Solution 25 - PythonHazrat aliView Answer on Stackoverflow
Solution 26 - PythondescriptView Answer on Stackoverflow
Solution 27 - Pythonsarath sahadevanView Answer on Stackoverflow
Solution 28 - PythonRAHUL KUMARView Answer on Stackoverflow
Solution 29 - Pythonuser3101152View Answer on Stackoverflow