What Requests is and why you need it
Requests is a Python library that lets you fetch web pages, send data to servers, and work with APIs without writing dozens of lines of code yourself. If you want to download a file from the internet, submit a form to a website, or pull data from an API, Requests handles the messy parts — authentication, headers, cookies, redirects — so you can focus on what you actually want to do.
It is not built into Python by default, so you have to install it first. The process takes two or three minutes and works the same way on Windows, Mac, and Linux.
Key Takeaways
- Requests installs through pip, Python's package manager, using a single command in your terminal or command prompt.
- You need Python and pip already installed on your machine; if you installed Python from python.org or used a package manager, pip came with it.
- The command pip install requests downloads and installs Requests in seconds, and you can verify it worked by importing it in Python.
- If pip is not found, you may need to use python -m pip install requests instead, or check that Python is in your system PATH.
- Virtual environments keep Requests and other packages isolated per project, which prevents version conflicts when you work on multiple projects.
Installing Requests with pip on Windows
Open Command Prompt by pressing Windows key + R, typing cmd, and pressing Enter. Type the following command and press Enter:
pip install requests
Pip will download Requests and any dependencies it needs, then print a success message. If you see "Successfully installed requests" at the end, you are done. If you see "pip is not recognized as an internal or external command", move to the troubleshooting section below.
To verify the install worked, open Python by typing python in the same Command Prompt window, then type import requests. If no error appears, Requests is installed and ready to use. Type exit() to close Python.
Installing Requests on Mac and Linux
Open Terminal. On Mac, press Command + Space, type "terminal", and press Enter. On Linux, open your terminal application from the applications menu or press Ctrl + Alt + T.
Type the following command and press Enter:
pip install requests
If you get a permission error, try pip3 install requests instead — this tells the system to use Python 3 explicitly, which is the standard on most modern machines. If that also fails, you may need to use sudo pip3 install requests, but this is less common and should only be necessary if pip is installed system-wide.
To verify, type python3 to open Python, then type import requests. If no error appears, the install worked. Type exit() to close Python.
Using a virtual environment to keep projects separate
A virtual environment is a folder on your machine that holds its own copy of Python and its own set of installed packages. This means you can install different versions of Requests (or any other library) for different projects without them interfering with each other.
To create a virtual environment, open your terminal or Command Prompt, navigate to the folder where you want to work, and type:
python -m venv myenv
Replace myenv with whatever name you want. This creates a folder called myenv. Now activate it by typing one of these commands depending on your system:
- Windows: myenv\Scripts\activate
- Mac or Linux: source myenv/bin/activate
Your terminal prompt will change to show the environment name in parentheses. Now type pip install requests as usual. Requests will install only in this environment, not system-wide. When you are done working, type deactivate to exit the environment.
Troubleshooting: pip not found or permission denied
If you see "pip is not recognized" on Windows, Python may not be in your system PATH. The easiest fix is to use python -m pip install requests instead of pip install requests. This tells Windows to run pip as a module of Python, which works even if pip is not in your PATH.
If you see a permission error on Mac or Linux, try pip3 install requests first. If that does not work, use a virtual environment instead of installing system-wide — this avoids permission issues entirely and is the standard practice for development work.
If Python itself is not found, you need to install Python first. Go to python.org, download the latest version for your operating system, and run the installer. On Windows, make sure to check the box that says "Add Python to PATH" during installation. Pip comes with Python automatically.
Verifying Requests works in your code
After installation, create a new Python file (or open an existing one) and add these lines at the top:
import requests
If the file runs without an ImportError, Requests is installed correctly. You can now use it to fetch web pages. For example, this code downloads the Google homepage:
response = requests.get('https://www.google.com')
The variable response now holds the server's reply, including the HTML content and status code. You can access the text with response.text or the status code with response.status_code. If this works without errors, your Requests installation is complete and functional.
Frequently Asked Questions
Do I need to install Requests every time I start Python?
No. You install Requests once, and it stays installed. Every time you run a Python script that imports Requests, Python finds the installed copy and uses it. You only reinstall if you uninstall it, switch to a new virtual environment, or upgrade to a new version of Python.
What is the difference between pip and pip3?
On systems with both Python 2 and Python 3 installed, pip usually refers to Python 2 and pip3 refers to Python 3. Since Python 2 is no longer supported, use pip3 on Mac and Linux if pip does not work. On Windows, pip typically points to Python 3 by default.
Can I use Requests with Python 2?
Requests does support Python 2, but Python 2 itself reached end of life in 2020 and is no longer maintained. New projects should use Python 3. If you are working with legacy code that requires Python 2, you can still install Requests, but you will not receive security updates.
How do I update Requests to a newer version?
Type pip install --upgrade requests or pip install -U requests. This downloads and installs the latest version, replacing the old one. You can also specify a version number: pip install requests==2.28.0 installs version 2.28.0 specifically.
What if I accidentally installed Requests in the wrong place?
Use a virtual environment for your next project. Virtual environments are isolated and separate, so you can start fresh without affecting your system Python or other projects. This is why most Python developers use them for every project, regardless of size.