I tried importing requests:
import requests
But I get an error:
ImportError: No module named requests
I tried importing requests:
import requests
But I get an error:
ImportError: No module named requests
Requests is not a built-in module (it does not come with the default Python installation), so you will have to install it:
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.
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.
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)
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)
sudo easy_install -U requestspip install requests to work (on a Mac) you need to use sudosudo pip3 install requestsIt'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.Brew users can use reference below,
command to install requests:
python3 -m pip install requests
pip is the package installer for Python and you need the package requests.
In my case requests was already installed, but needed an upgrade. The following command did the trick
$ sudo pip install requests --upgrade
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.
No module named urllib3 :)pip install requests
then use it inside your Python script by:
import requests
piprequests package and install itIf 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.
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
python -m pip install requests
or
python3 -m pip install requests
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.
Facing the same issue but unable to fix it with the above solution, so I tried this way and it worked:
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python2 get-pip.py
python -m pip install requests
pip install requestssudo with the pip command if possibleFor 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...
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.
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.
if you want request import on windows:
pip install request
then beautifulsoup4 for:
pip3 install beautifulsoup4
I found that my issue was VSCode was reading from the wrong Python Interpreter. This youtube tutorial solved it for me.
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
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.
Follow the below steps to resolve this issue. I tried this in Windows - VS Code. The issue got resolved.
py -m venv venv.\venv\Scripts\activatepip install requestspy abc.py
requests, usingpiporeasy_install?pythonis not seeing those modules. Usingpython2.7, everything is working. I suppose I need to clean up my environment a bit.