How to Install requests Package in Python – Windows, macOS, and Linux
In this tutorial, you’ll learn how to install the popular requests package in Python, including on Windows, macOS, and Linux. The requests library is a popular HTTP library that can handle generating different types of requests, including GET , POST , and PUT requests. The library is available for Python 3 from the Python Package Index (PyPI).
By the end of this tutorial, you’ll have learned:
- How to install the requests library in Python for Windows, macOS, and Linux using the pip package manager
- How to install the requests library using a Virtual Environment and a requirements.txt file
- How to install requests from Github
Table of Contents
What is the Python requests Library?
The Python requests library is a Python library that handles making HTTP requests. The library is well known for being simple and elegant, by abstracting away much of the complexity of working with HTTP requests. The library is also one of the more popular libraries available in Python: it currently draws around 30,000,000 downloads per week and is in use by over 1,000,000 repositories on Github.
How to Install requests on Windows Using pip
The simplest way to install the requests library on Windows is to use the Python pip package manager. In order to install the latest version of the library, you can simply call the following command in the command prompt:
To install a specific version of the library, such as version 2.28.1, you can write the following command:
It’s as easy as that! In the following section, you’ll learn how to install the requests library on macOS using the pip package manager.
How to Install requests on macOS Using pip
Similar to the Windows method, the simplest way to install the requests library on macOS is by using the pip package manager. On macOS, this is done by using the Terminal application. When in the Terminal application, simply run the following command:
Similar to installing a specific version on Windows, to install a specific version of the library, such as version 2.28.1, you can write the following command:
In the following section, you’ll learn how to install the requests library on Linux.
How to Install requests on Linux Using pip
To install the requests library using the pip package manager on Linux, you can use the terminal application. When the application is open, you can run the following command:
Similar to the above example, to install a specific version of the library, such as version 2.28.1, you can write the following command:
In the following section, you’ll learn how to install the requests library in a virtual environment.
How to Install requests in a Virtual Environment
Using a virtual environment is a good idea for many reasons. For one, it allows you to better understand what versions of libraries you’re using. Additionally, it allows you to keep a cleaner development environment.
Installing the requests library in a virtual environment works the same as the methods above, though we first have to create and activate the virtual environment. You can create and activate the environment on Windows using the method below:
On macOS, you can write the following:
Once the environment has been created, you can use any of the pip methods shown above to install the requests library. This is summarized in the code block below:
In the following section, you’ll learn how to install the library using a requirements.txt file.
How to Install requests With requirements.txt
Using a requirements.txt file is particularly helpful when sharing your code with others via source code management tools, such as Github. The file provides the ability to easily track and identify the packages that you use in a project.
In order to use the requirements.txt file to install the requests library, you can insert a file name requirements.txt to the root folder of your project. In the file, include a line containing requests .
From there, you can use the pip package manager to install all libraries listed in the file. This can be done using the following command:
In the final section below, you’ll learn how to install the requests library directly from Github source code.
How to Install requests from Github
If you have Git installed, you can install the requests library directly from the source code. This allows you to install the library from its code directly.
In order to do that, you can use the pip package manager, though you pass in the URL to the source code directly.
Doing this can help you feel confident that the code you’re installing is the code you want to use.
Requests
Requests is a simple, yet elegant, HTTP library.
Requests allows you to send HTTP/1.1 requests extremely easily. There’s no need to manually add query strings to your URLs, or to form-encode your PUT & POST data — but nowadays, just use the json method!
Requests is one of the most downloaded Python packages today, pulling in around 30M downloads / week — according to GitHub, Requests is currently depended upon by 1,000,000+ repositories. You may certainly put your trust in this code.
Installing Requests and Supported Versions
Requests is available on PyPI:
Requests officially supports Python 3.7+.
Supported Features & Best–Practices
Requests is ready for the demands of building robust and reliable HTTP–speaking applications, for the needs of today.
Requests в Python – Примеры выполнения HTTP запросов
Библиотека requests является стандартным инструментом для составления HTTP-запросов в Python. Простой и аккуратный API значительно облегчает трудоемкий процесс создания запросов. Таким образом, можно сосредоточиться на взаимодействии со службами и использовании данных в приложении.
Содержание статьи
В данной статье представлены наиболее полезные особенности requests. Показано, как изменить и приспособить requests к различным ситуациям, с которыми программисты сталкиваются чаще всего. Здесь также даются советы по эффективному использованию requests и предотвращению влияния сторонних служб, которые могут сильно замедлить работу используемого приложения. Мы использовали библиотек requests в уроке по парсингу html через библиотеку BeautifulSoup.
Ключевые аспекты инструкции:
- Создание запросов при помощи самых популярных HTTP методов;
- Редактирование заголовков запросов и данных при помощи строки запроса и содержимого сообщения;
- Анализ данных запросов и откликов;
- Создание авторизированных запросов;
- Настройка запросов для предотвращения сбоев и замедления работы приложения.
В статье собран оптимальный набор информации, необходимый для понимания данных примеров и особенностей их использования. Информация представлена в доступной в форме. Тем не менее, стоит иметь в виду, что для оптимального разбора инструкции потребуются хотя бы базовые знания HTTP.
Далее будут показаны наиболее эффективные методы использования requests в разрабатываемом приложении.
Python установка библиотеки requests
Для начала работы потребуется установить библиотеку requests . Для этого используется следующая команда.
Есть вопросы по Python?
На нашем форуме вы можете задать любой вопрос и получить ответ от всего нашего сообщества!
Как установить модуль requests
Requests is an elegant and simple HTTP library for Python, built for human beings. One of the most famous libraries for python used by developers al over the world. This article revolves around how one can install requests library of python in Windows/ Linux/ macOS, etc.
Installation
Windows
For installing requests in windows, one would require Python (preferably latest version), so if you don’t have python installed, head to – How to download and install Python Latest Version on Windows. Now open command prompt from the windows and run following command –
Booom. Done Now, requests library is downloaded successfully.
Linux
For installing requests in linux, one would require Python (preferably latest version) and pip latest version, so if you don’t have python installed, head to – How to download and install Python Latest Version on Linux. To install pip in linux – How to install PIP in Linux?. Now run,
macOS
For installing requests in mac, one would require Python (preferably latest version) and pip latest version, so if you don’t have python installed, head to – How to download and install Python Latest Version on mac. To install pip mac Os. Run,
Now to install requests,
Alternative common method
THe last method for installation of requests on any operating system is to grab the base files and install requests manually and Requests is actively developed on GitHub, where the code is always available. For code – visit here.
You can either clone the public repository:
Or, download the tarball:
Once you have a copy of the source, you can embed it in your own Python package, or install it into your site-packages easily: