909

I tried importing requests:

import requests

But I get an error:

ImportError: No module named requests

Mateen Ulhaq
  • 24,552
  • 19
  • 101
  • 135
user2476540
  • 9,265
  • 4
  • 15
  • 9
  • 33
    Did you install `requests`, using `pip` or `easy_install`? – Thomas Orozco Jun 25 '13 at 23:36
  • 25
    I get same issue, I installed via pip – David Crook Aug 14 '16 at 17:06
  • 1
    just to note, I only get the issue from within Spyder, but not the cmd prompt. – David Crook Aug 14 '16 at 17:07
  • @DavidCrook Did you got the solution? I have the same issue with only my IDE. – Vicrobot Jun 24 '18 at 17:14
  • 5
    I get the same result. pip3 reports "Requirement already satisfied:..." – Matt Jul 08 '18 at 16:14
  • I solved it; but I can-not recall how I did it. My guess is that since I was using from Spyder; I was likely in a different environment than I thought I was in and needed to install requests into the environment spyder was using in the IDE. – David Crook Jul 10 '18 at 16:04
  • 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. – Sean Novak Oct 19 '18 at 11:47
  • requests module needs "charset_normalizer-3.1.0-cp310-cp310-win_amd64.whl". When I installed using pip(pip3) the result is as shown: Collecting requests Using cached requests-2.30.0-py3-none-any.whl (62 kB) Collecting charset-normalizer<4,>=2 (from requests) Using cached charset_normalizer-3.1.0-cp310-cp310-win_amd64.whl (97 kB) It worked well. Please check whether the supported modules exist – Venkatarao Dadi May 21 '23 at 14:03

34 Answers34

1082

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

OSX/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 python3)

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 Python2: sudo apt-get install python-requests

For Debian/Ubuntu Python3: sudo apt-get install python3-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)

TheoretiCAL
  • 19,461
  • 8
  • 43
  • 65
  • 8
    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. (http://stackoverflow.com/questions/3220404/why-use-pip-over-easy-install) – Chris Aug 10 '13 at 14:25
  • 13
    for centos: yum install python-requests – Erik Aronesty Dec 20 '13 at 18:47
  • I got this:`Wheel installs require setuptools >= 0.8 for dist-info support. pip's wheel support requires setuptools >= 0.8 for dist-info support.`, so frustrating. –  Mar 03 '14 at 03:25
  • 11
    On mac os x, if you have easy_install installed, you can also use: `sudo easy_install -U requests` – RobinCominotto Mar 16 '14 at 17:00
  • 12
    Note for posterity: for `pip install requests` to work (on a Mac) you need to use `sudo` – David Oneill May 20 '14 at 13:40
  • shouldn't it be `> Path\easy_install.py requests` – cbunn Feb 03 '15 at 19:40
  • On Linux, why do you need sudo for the command to work? It wouldn't work for me until I used sudo but they say you're not supposed to use sudo and pip together. Thanks in advance for the explanation. – BourbonCreams Jul 19 '17 at 11:35
  • 1
    @BourbonCreams depending on the privileges of the user you are currently logged in as, you may not have access to write in the system level directories, which get updated depending on what you install. As a result you use sudo to essentially give yourself root privileges to when executing the command, which ensures you have write access to system directories. – TheoretiCAL Jul 19 '17 at 18:02
  • In Java it is common practice to package dependencies with a project in a `Libraries` folder. Does Python have a similar practice? Or does each developer need to install Requests on their own machine? – Stevoisiak Oct 27 '17 at 16:52
  • 7
    got it working on Mac OS X using: `sudo pip3 install requests` – herrera May 03 '18 at 21:52
  • Windows: Had to add dir with Pip.exe to Path Environment Variable. Then worked well. – Brent Oct 19 '18 at 12:54
  • `sudo apt install python-requests` will work on Kubuntu 18.04. – kavadias Oct 22 '18 at 10:47
  • i had to restart the terminal after installing requests. – dresh Mar 30 '19 at 05:30
  • `apt-get install python3-requests` for python3 – user3132194 Apr 21 '21 at 07:05
  • if i have python3 is there any difference between `pip install` and `pip3 install`? – MichalH Nov 06 '21 at 19:10
  • 1
    @MichalH if you have multiple versions of python on your machine (python2.* and python3.*) then you could use pip3 to ensure your installing for python 3. If you just have python3 on your machine, then you can use either. – TheoretiCAL Jan 22 '22 at 18:09
99

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

Stephan Kristyn
  • 15,015
  • 14
  • 88
  • 147
SamPutnam
  • 1,129
  • 7
  • 7
  • 3
    `sudo pip3 install requests` if you want it installed for all users on a machine, not just one user. – Adrian Feb 13 '18 at 15:46
78

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

Subinoy
  • 478
  • 7
  • 22
Deming
  • 1,210
  • 12
  • 15
46

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.

ymutlu
  • 6,585
  • 4
  • 35
  • 47
37

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

dee cue
  • 983
  • 1
  • 7
  • 23
27

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
Awais
  • 1,803
  • 22
  • 26
20

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

$ sudo pip install requests --upgrade
bobbydev
  • 525
  • 3
  • 12
18

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
iosCurator
  • 4,356
  • 2
  • 21
  • 25
  • 2
    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. – shjeff Aug 24 '18 at 14:07
  • 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. – John Pitts Mar 14 '20 at 14:17
14

On Windows Open Command Line

pip3 install requests
saigopi.me
  • 14,011
  • 2
  • 83
  • 54
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.

bigboss21
  • 137
  • 1
  • 3
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
smci
  • 32,567
  • 20
  • 113
  • 146
mamal
  • 1,791
  • 20
  • 14
  • 1
    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. – smci Jun 22 '20 at 02:30
  • 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. – smci Jul 14 '20 at 10:05
  • 1
    Please prove your point with the document 99%!!! or 85%!!! @smci – mamal Jul 14 '20 at 10:10
  • 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. – smci Jul 14 '20 at 10:15
  • 1
    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. – Eugene Dec 08 '20 at 02:26
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.

Arnab Biswas
  • 4,495
  • 3
  • 42
  • 60
  • 1
    I needed requests_ntlm, so had to run "conda config --add channels conda-forge" then "conda install -c anaconda requests_ntlm" – Zunair May 31 '19 at 19:30
7

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.

krishna kanth
  • 71
  • 1
  • 1
7

Try sudo apt-get install python-requests.

This worked for me.

Sarvagya Gupta
  • 861
  • 3
  • 13
  • 28
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
Joviano Dias
  • 1,043
  • 10
  • 13
7

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?

Community
  • 1
  • 1
RandyMcMillan
  • 59
  • 2
  • 3
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

Kumar Pankaj Dubey
  • 1,541
  • 3
  • 17
  • 17
6

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...

Robert
  • 5,278
  • 43
  • 65
  • 115
jazz
  • 61
  • 1
  • 1
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.

ajsmart
  • 193
  • 1
  • 11
  • 1
    Gave that a try on oracle linux (basically RHEL) but didn't work. Posting so others can know about this result. Thanks though~ – interestedparty333 Jan 19 '18 at 20:30
  • @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. – ajsmart Jan 20 '18 at 16:07
  • 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. :) – interestedparty333 Jan 20 '18 at 23:17
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

Tina
  • 37
  • 2
  • 5
Andreas Bigger
  • 5,264
  • 1
  • 13
  • 18
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.

3

if you want request import on windows:

pip install request

then beautifulsoup4 for:

pip3 install beautifulsoup4
Ronald Rink 'd-fens'
  • 1,289
  • 1
  • 10
  • 27
Sefa AYDIN
  • 31
  • 2
  • 2
    I think what you mean is "requests" not "request". There is no library named "request" – Ethan Jul 16 '20 at 12:39
3

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.

Andrew
  • 375
  • 3
  • 10
3

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 
Jamiu S.
  • 5,257
  • 5
  • 12
  • 34
3

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

pip install requests
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

gus
  • 532
  • 4
  • 6
2

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

Alice
  • 612
  • 1
  • 5
  • 13
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
descript
  • 99
  • 1
  • 6
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.

AlixaProDev
  • 472
  • 1
  • 5
  • 13
0

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

0

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

sudo pip3 install requests
RAHUL KUMAR
  • 1,123
  • 11
  • 9
0

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

user3101152
  • 51
  • 1
  • 2
0

Following this tutorial:

$ pipenv install requests
Installing requests...
Adding requests to Pipfile's [packages]...
 Installation Succeeded 
Pipfile.lock not found, creating...
Locking [dev-packages] dependencies...
Locking [packages] dependencies...
Building requirements...
Resolving dependencies...
 Success! 
Updated Pipfile.lock (a290a1)!
Installing dependencies from Pipfile.lock (a290a1)...
   ▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉▉ 0/0 — 00:00:00
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
$ pipenv shell
Launching subshell in virtual environment...
 . /home/[user]/.local/share/virtualenvs/[id]/bin/activate
$ python3
Python 3.10.5 (main, Jul  5 2022, 00:20:23) [GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import requests
>>> response = requests.get('https://httpbin.org/ip')
>>> print('Your IP is {0}'.format(response.json()['origin']))
Your IP is xx.xxx.xx.xxx
Erwann
  • 113
  • 1
  • 7
0

What did actually work for me, and is going to work for you is to find out the path of yours scripts folder

  1. For example C:\Python31\Scripts
  2. Via CMD, navigate with CD to this folder
  3. Type > pip, to see wether is there/it does work
  4. pip install requests; or any other packages that produces the error.
  5. Done

Operation done

Best Regards, Roman

Roman
  • 43
  • 8
  • thank you for your efforts to provide an answer. How is you answer any different from the existing ones ? at the end you just install requests as suggested in the best answer. – Pierrick Rambaud Aug 02 '23 at 17:55