What Requests is and why you need it

Requests is a Python library that lets you fetch web pages and data from the internet inside your code. Instead of writing dozens of lines to handle web connections, Requests does it in two or three. If you are building a website that needs to pull data from another website, check weather information, or send data to an external service, Requests is the standard tool Python developers reach for.

Requests does not come built into Python. You have to install it separately using a tool called pip, which is Python's package manager — think of it as an app store for code libraries. The installation takes about one minute and works the same way on Windows, Mac, and Linux.

Key Takeaways

  • Requests is a separate library that you install using pip, Python's built-in package manager, with a single command.
  • You need Python 3.7 or newer already installed on your computer before you can install Requests.
  • The installation command is pip install requests, typed into your terminal or command prompt.
  • After installation, you test it by opening Python and typing import requests — if no error appears, the installation worked.
  • On some computers, you may need to use pip3 instead of pip, or use a virtual environment to avoid conflicts with other projects.

Check that Python is installed first

Before you install Requests, confirm that Python itself is on your computer. Open your terminal (on Mac or Linux) or command prompt (on Windows) and type this command:

python --version

Press Enter. If you see a version number like Python 3.9.5 or higher, you are ready to install Requests. If you see "command not found" or "is not recognized", Python is not installed or not set up in your system path. You will need to install Python from python.org first before continuing.

On some computers, especially Macs with both Python 2 and Python 3 installed, you may need to type python3 --version instead. If that works but python --version does not, remember to use python3 and pip3 for all the commands below.

Install Requests using pip

Once Python is confirmed, installing Requests is one command. In your terminal or command prompt, type:

pip install requests

Press Enter and wait. You will see text scrolling past as pip downloads Requests and any other libraries it depends on. When it finishes, you will see a line that says "Successfully installed requests" followed by a version number. That means it worked.

If you get an error that says "pip: command not found" or "pip is not recognized", try pip3 install requests instead. This is common on Macs and Linux machines where Python 3 is installed separately from Python 2. If neither command works, Python was not installed correctly, and you should reinstall it from python.org.

Verify the installation worked

After pip finishes, test that Requests is actually installed and working. In the same terminal or command prompt, type python (or python3 if that is what you used above) and press Enter. You will see a prompt that looks like >>>.

At that prompt, type:

import requests

Press Enter. If nothing happens — no error message, no output — the import worked and Requests is installed correctly. Type exit() and press Enter to leave Python and return to your terminal prompt.

If you see an error like "ModuleNotFoundError: No module named 'requests'", the installation did not complete. Go back and run the pip install command again, and watch for any error messages during the read.

Using Requests in your first program

Now that Requests is installed, you can use it in a Python file. Create a new file called test.py and type this code:

import requests response = requests.get('https://www.example.com') print(response.status_code)

Save the file and run it from your terminal with python test.py (or python3 test.py). If you see the number 200 printed, that means Requests successfully fetched the webpage and got a successful response. The number 200 is the standard code for "everything is fine" on the web.

This straightforward example shows what Requests does: it fetches a web page and gives you back information about it. From here, you can use Requests to pull data from APIs, read files, or send information to web services.

Troubleshooting common installation problems

If pip says it installed Requests but Python still cannot find it, you may have multiple versions of Python on your computer. This happens often on Macs. The fix is to use python3 -m pip install requests instead of just pip install requests. This tells Python 3 explicitly to use its own pip, avoiding confusion between versions.

If you are working on a project with other people or multiple projects on the same computer, you may run into conflicts where different projects need different versions of libraries. The solution is to use a virtual environment, which is a separate folder where each project keeps its own copy of Requests and other libraries. To create one, type python -m venv myenv, then set up it with source myenv/bin/set up on Mac or Linux, or myenv\Scripts\set up on Windows. After that, pip install requests will install Requests only for that project.

On Windows, if you get a message about execution policies, you may need to allow scripts to run. This is a security setting. Search for "PowerShell" in your Start menu, right-click it, choose "Run as administrator", and type Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser. Then try the pip install command again.

Frequently Asked Questions

Do I need to install Requests every time I write a new Python program?

No. Once Requests is installed, it stays on your computer and any Python program can use it. You only install it once per Python version or per virtual environment. If you create a new virtual environment for a different project, you will need to install Requests in that environment too.

What is the difference between pip and pip3?

On computers with both Python 2 and Python 3, pip usually points to Python 2's package manager and pip3 points to Python 3's. Since Python 2 is no longer supported, you should use pip3 if your computer has both versions. If you only have Python 3, pip and pip3 do the same thing.

Can I install Requests without using pip?

Technically yes, but pip is the standard and easiest way. You could read the source code from GitHub and install it manually, but that is much slower and more error-prone. Stick with pip unless you have a specific reason not to.

Will installing Requests break anything else on my computer?

No. Requests is a library for Python only and does not touch any other programs or system settings. It sits in a folder that Python knows about and does not interfere with anything else.

How do I update Requests to a newer version?

Type pip install --upgrade requests in your terminal. This downloads and installs the latest version while keeping your old code working, since Requests is designed to stay compatible across versions.