Whenever I try to import requests
, I get an error saying No module Named requests
.
import requests
The error I get:
File "ex2.py", line 1, in <module>
import requests
ImportError: No module named requests
Whenever I try to import requests
, I get an error saying No module Named requests
.
import requests
The error I get:
File "ex2.py", line 1, in <module>
import requests
ImportError: No module named requests
Requests is not a built in module (does not come with the default python installation), so you will have to install it:
Use $ sudo pip install requests
if you have pip
installed
Alternatively you can also use sudo easy_install -U requests
if you have easy_install
installed.
For centos: yum install python-requests
Use pip install requests
if you have pip
installed and Pip.exe added to the Path Environment Variable.
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 don't have easy install and are running on a windows machine, you can get it here: http://www.lfd.uci.edu/~gohlke/pythonlibs/#distribute
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
)
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.
sudo easy_install -U requests
– RobinCominotto
Mar 16 '14 at 17:00
pip install requests
to work (on a Mac) you need to use sudo
– David Oneill
May 20 '14 at 13:40
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
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
To install requests
module on Debian/Ubuntu:
$ sudo apt-get install python-requests
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
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
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.
In my case requests was already installed, but needed an upgrade. The following command did the trick
$ sudo pip install requests --upgrade
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...
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
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
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.
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.
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.
if you want request
import on windows:
pip install request
then beautifulsoup4
for:
pip3 install beautifulsoup4
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
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
My problem was that I had four different python libraries that python was trying to use (even though I was explicitly calling /usr/bin/python
). Once I removed a shell alias and two other pythons from my path, /usr/bin/python
was able to import requests
.
-HTH
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
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.
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
The issue could be because of a machine having multiple versions of Python. Make sure that you are installing Request modules in all the versions.
In my case, I had python version 2.7
and 3.7
. I resolved this issue by installing with both versions of python
you can also use pip install on windows by first locating the pip3.exe file in the directory: say for me==> cd c:\python34\scripts then run ==> pip3 install requests
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
requests
, usingpip
oreasy_install
? – Thomas Orozco Jun 25 '13 at 23:36