983

I tried importing requests:

import requests

But I get an error:

ImportError: No module named requests

9
  • 41
    Did you install requests, using pip or easy_install? Commented Jun 25, 2013 at 23:36
  • 32
    I get same issue, I installed via pip Commented Aug 14, 2016 at 17:06
  • 1
    just to note, I only get the issue from within Spyder, but not the cmd prompt. Commented Aug 14, 2016 at 17:07
  • 6
    I get the same result. pip3 reports "Requirement already satisfied:..." Commented Jul 8, 2018 at 16:14
  • 2
    For me, it turned out to be a conflict with multiple installations of python. For instance, on my mac, somehow I've acquired python AND python2.7 in /usr/bin, which do not symlink to the same installation. Though pip, apparently, is installing modules for python2.7. Thus, python is not seeing those modules. Using python2.7, everything is working. I suppose I need to clean up my environment a bit. Commented Oct 19, 2018 at 11:47

39 Answers 39

1177

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

Mac OS X and Linux

Python 2: sudo pip install requests

Python 3: sudo pip3 install requests

if you have pip installed (pip is the package installer for Python and should come by default with your Python installation). If pip is installed, but not in your path, you can use python -m pip install requests (or python3 -m pip install requests for Python 3)

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

Linux

Alternatively you can use your systems package manager:

For CentOS: sudo yum install python-requests

For Debian/Ubuntu Python 2: sudo apt-get --reinstall install python-requests

For Debian/Ubuntu Python 3: sudo apt-get --reinstall install python3-requests

--reinstall may fix this error, if package was already installed.

Windows

Use pip install requests (or pip3 install requests for Python 3) 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 Python 3)

Alternatively, from a command 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 OS X and Windows, after downloading the source ZIP file, uncompress it and from the terminal/cmd, run python setup.py install from the uncompressed directory.

(Source)

Sign up to request clarification or add additional context in comments.

17 Comments

If any of you have pip installed on Windows, "pip install requests" will work just fine. I'm guessing that "easy_install requests" will work on osx/linux as well, but pip is generally preferred. (stackoverflow.com/questions/3220404/…)
for centos: yum install python-requests
On mac os x, if you have easy_install installed, you can also use: sudo easy_install -U requests
Note for posterity: for pip install requests to work (on a Mac) you need to use sudo
got it working on Mac OS X using: sudo pip3 install requests
|
104

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

1 Comment

sudo pip3 install requests if you want it installed for all users on a machine, not just one user.
79

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

Comments

50

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.

3 Comments

Would you care to add a brief explanation (here) of why this works?
Added extra comment for pip info.
I had to change the python to ~/anaconda3/envs/<env_name>/bin/python3 -m pip install requests `
42

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

Comments

29

If you are using Ubuntu, there is a need to install Requests.

Run this command:

pip install requests

If you face a permission denied error, use sudo before the command:

sudo pip install requests

1 Comment

I am on Mint and am getting the same error even though it is installed.
20

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

$ sudo pip install requests --upgrade

1 Comment

I tried this and it's still not working. How do I get it to work?
19

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

2 Comments

I didn't noticed difference, but it does matter. I have installed python 3.7 version, and requests using pip and it couldn't find it. When I installed via pip3 it works now.
Tried 'sudo pip3 install requests' and it seeed to download, but then when running the file with requests in it, got the typical "ImportError: No module named requests". So frustrating.
14

On Windows Open Command Line

pip3 install requests

Comments

12

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

2 Comments

Now I've got No module named urllib3 :)
@PavelAlexeev try executing this command before "pip install urllib3"
11

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

5 Comments

The OP never said anything about pycharm, 99% of users don't use pycharm, and it is totaly unnecessary to use pycharm to install a package, that's a one-line command-line task. Shouldn't even mention pycharm here.
Yes, 99% of Python users don't use pycharm. Like I said. Ok maybe 'only' 85% don't use it, even if we take JetBrains own numbers. I've personally never seen JetBrains used for Python development inside an org, and only ever heard of it being used in Java-dominated shops. The point again is that the OP never asked for an IDE-specific solution.
Please prove your point with the document 99%!!! or 85%!!! @smci
I already told you above what numbers prove that: JetBrains' own numbers(!!!). Even allowing that JetBrains understate the many developers who don't use an IDE, but use vi/emacs.
lovely answer! for someone who coded in java for 15 years and loves JetBrain tools, pycharm is the first option. This helped me, thx a lot.
9

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.

1 Comment

I needed requests_ntlm, so had to run "conda config --add channels conda-forge" then "conda install -c anaconda requests_ntlm"
9

In case you hit pip install requests and had an output massage of Requirement already satisfied but yet you still get the error: ImportError: No module named requests.

This is likely to happen when you find yourself in a different interpreter/virtual environment.

You can copy and append the path of the module into your working environment.
Note: This path usually comes with the message Requirement already satisfied

Before import requests, you should import sys and then append the copied path.

Example:
Command Prompt:
pip install requests
Output:
Requirement already satisfied: requests in /usr/local/lib/python3.9/site-packages

import sys
sys.path.append("/usr/local/lib/python3.9/site-packages")
import requests 

1 Comment

The same issue here. I simply delete the folder venv and recreate it.
8

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?

Comments

7

Try sudo apt-get install python-requests.

This worked for me.

Comments

7

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

Comments

7

Adding Third-party Packages to the Application

Follow this link: Source

Step 1: 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.

1 Comment

This was actually what I was looking for. The above steps alone didn't work for AppEngine :)
7

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

2 Comments

Number 3) you can also simply run pip install requests
please avoid using sudo with the pip command if possible
6

For Windows, just give the path as cd and the path to the "Scripts" of the Python interpreter.

And execute the command easy_install.exe requests. Then try import requests...

2 Comments

What do you mean by "give the path as cd"?
What is "easy_install.exe"?
5

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.

3 Comments

Gave that a try on oracle linux (basically RHEL) but didn't work. Posting so others can know about this result. Thanks though~
@ragerdl Your issue may not specifically be with requests or urllib3. It could be with other python packages. It just depends on what you are trying to run.
Indeed, I had two bad pythons in my path and an alias to a bad python too. Getting rid of those three python pointers resolved my issue. :)
4

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

Comments

4

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.

Comments

4

Type this command in Command Prompt (Windows) or Terminal (Linux/macOS):

pip install requests

Comments

3

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.

Comments

3

if you want request import on windows:

pip install request

then beautifulsoup4 for:

pip3 install beautifulsoup4

1 Comment

I think what you mean is "requests" not "request". There is no library named "request"
2

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

Comments

2

I found that my issue was VSCode was reading from the wrong Python Interpreter. This youtube tutorial solved it for me.

1 Comment

Please do not link to youtube tutorials. They are stale and will go out of date, and are not necessarily available to everyone
1

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

Comments

1

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.

Comments

1

Follow the below steps to resolve this issue. I tried this in Windows - VS Code. The issue got resolved.

  1. Create a virtual environment py -m venv venv
  2. Activate the virtual environment .\venv\Scripts\activate
  3. Install the library pip install requests
  4. Run your python program py abc.py

1 Comment

I have faced the same issue but it resolved simply in two steps (as i am using vs code terminal) keep this in mind which IDE or MacOS or Linux Or windows your using so give them accordingly. 1) py -m pip install requests 2) python app.py (Note: In my case python3 app.py is not worked for it)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.