Python pip requests windows

Installing packages using pip and virtual environments¶

This guide discusses how to install packages using pip and a virtual environment manager: either venv for Python 3 or virtualenv for Python 2. These are the lowest-level tools for managing Python packages and are recommended if higher-level tools do not suit your needs.

This doc uses the term package to refer to a Distribution Package which is different from an Import Package that which is used to import modules in your Python source code.

Installing pip¶

pip is the reference Python package manager. It’s used to install and update packages. You’ll need to make sure you have the latest version of pip installed.

Debian and most other distributions include a python-pip package; if you want to use the Linux distribution-provided versions of pip, see Installing pip/setuptools/wheel with Linux Package Managers .

You can also install pip yourself to ensure you have the latest version. It’s recommended to use the system pip to bootstrap a user installation of pip:

python3 -m pip install --user --upgrade pip python3 -m pip --version

Afterwards, you should have the latest version of pip installed in your user site:

pip 21.1.3 from $HOME/.local/lib/python3.9/site-packages (python 3.9)

The Python installers for Windows include pip. You can make sure that pip is up-to-date by running:

py -m pip install --upgrade pip py -m pip --version

Afterwards, you should have the latest version of pip:

pip 21.1.3 from c:\python39\lib\site-packages (Python 3.9.4)

Installing virtualenv¶

If you are using Python 3.3 or newer, the venv module is the preferred way to create and manage virtual environments. venv is included in the Python standard library and requires no additional installation. If you are using venv, you may skip this section.

virtualenv is used to manage Python packages for different projects. Using virtualenv allows you to avoid installing Python packages globally which could break system tools or other projects. You can install virtualenv using pip.

python3 -m pip install --user virtualenv
py -m pip install --user virtualenv

Creating a virtual environment¶

venv (for Python 3) and virtualenv (for Python 2) allow you to manage separate package installations for different projects. They essentially allow you to create a “virtual” isolated Python installation and install packages into that virtual installation. When you switch projects, you can simply create a new virtual environment and not have to worry about breaking the packages installed in the other environments. It is always recommended to use a virtual environment while developing Python applications.

Читайте также:  Webstorm eslint for typescript

To create a virtual environment, go to your project’s directory and run venv. If you are using Python 2, replace venv with virtualenv in the below commands.

The second argument is the location to create the virtual environment. Generally, you can just create this in your project and call it env .

venv will create a virtual Python installation in the env folder.

You should exclude your virtual environment directory from your version control system using .gitignore or similar.

Activating a virtual environment¶

Before you can start installing or using packages in your virtual environment you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH .

You can confirm you’re in the virtual environment by checking the location of your Python interpreter:

Источник

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:

 python -m pip install requests

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.

  • Keep-Alive & Connection Pooling
  • International Domains and URLs
  • Sessions with Cookie Persistence
  • Browser-style TLS/SSL Verification
  • Basic & Digest Authentication
  • Familiar dict –like Cookies
  • Automatic Content Decompression and Decoding
  • Multi-part File Uploads
  • SOCKS Proxy Support
  • Connection Timeouts
  • Streaming Downloads
  • Automatic honoring of .netrc
  • Chunked HTTP Requests

API Reference and User Guide available on Read the Docs

Cloning the repository

When cloning the Requests repository, you may need to add the -c fetch.fsck.badTimezone=ignore flag to avoid an error about a bad commit (see this issue for more background):

git clone -c fetch.fsck.badTimezone https://github.com/psf/requests.git

You can also apply this setting to your global Git config:

git config --global fetch.fsck.badTimezone ignore

Источник

How to Install requests Package in Python – Windows, macOS, and Linux

How to install Python requests library cover image

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

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:

python -m pip install requests

To install a specific version of the library, such as version 2.28.1, you can write the following command:

python -m pip install requests==2.28.1

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:

python -m venv venv .\venv\Scripts\activate

On macOS, you can write the following:

virtualenv venv source venv/bin/activate

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:

# On Windows: python -m pip install requests # On macOS or Linux pip install requests

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:

pip install -r requirements.txt

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.

pip install github.com/kennethreitz/requests.git

Doing this can help you feel confident that the code you’re installing is the code you want to use.

Conclusion

In this tutorial, you learned how to install the requests library on Windows, macOS, and Linux. You first learned how to install the library using the pip package manager. Then, you learned how to install the library in a virtual environment. Finally, you learned how to install the library using a requirements.txt file as well as directly from Github.

Additional Resources

To learn more about related topics, check out the tutorials below:

Источник

Installation of Requests¶

https://farm5.staticflickr.com/4230/35550376215_da1bf77a8c_k_d.jpg

This part of the documentation covers the installation of Requests. The first step to using any software package is getting it properly installed.

$ pipenv install requests¶

To install Requests, simply run this simple command in your terminal of choice:

If you don’t have pipenv installed (tisk tisk!), head over to the Pipenv website for installation instructions. Or, if you prefer to just use pip and don’t have it installed, this Python installation guide can guide you through the process.

Get the Source Code¶

Requests is actively developed on GitHub, where the code is always available.

You can either clone the public repository:

$ git clone git://github.com/requests/requests.git
$ curl -OL https://github.com/requests/requests/tarball/master # optionally, zipball is also available (for Windows users).

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:

Requests is an elegant and simple HTTP library for Python, built for human beings. You are currently looking at the documentation of the development release.

Stay Informed

Receive updates on new releases and upcoming projects.

Other Projects

  • Open DSM-5M
  • Requests-HTML
  • howtopython.org
  • pipenv
  • pep8.org
  • httpbin.org
  • The Python Guide
  • Maya: Datetimes for Humans
  • Records: SQL for Humans
  • Legit: Git for Humans
  • Tablib: Tabular Datasets

Translations

Table of Contents

Источник

Оцените статью