Since Requests belongs to a third-party library, that is, Python does not come with this library by default, so we need to install it manually. Let's first take a look at its installation process.
1. Related Links
-
Official document: http://www.python-requests.org
-
Chinese document: http://docs.python-requests.org/zh_CN/latest
-
2. pip installation
Whether it is Windows, Linux or Mac, you can install it through pip, a package management tool.
Run the following command in the command line interface to complete the installation of the Requests library:
pip3 install requests
This is the easiest way to install, and it is recommended to use this method of installation.
3.wheel installation
wheel is an installation package of Python with a suffix of .whl. In the case of poor internet speed, you can choose to download the wheel file and install it, and then install it directly with the pip3
command and the file name.
But before that, you need to install the wheel library first. The installation command is as follows:
pip3 install wheel
Then download the corresponding wheel file on PyPI. If the latest version is 2.17.3, open https://pypi.python.org/pypi/requests/2.17.3#downloads and download requests-2.17.3-py2.py3 -none-any.whl to the local.
Then enter the wheel file directory on the command line interface and pip
install it:
pip3 install requests-2.17.3-py2.py3-none-any.whl
In this way, we can also complete the installation of Requests.
4. Source installation
If you don't want to use pip to install, or want to get a specific version, you can choose to download the source code to install.
In this way, you need to find the source code address of this library first, then download it and install it with the command.
The address of the Requests project is: https://github.com/kennethreitz/requests .
You can download the source code through Git:
git clone git://github.com/kennethreitz/requests.git
Or by curl
downloading:
curl -OL https://github.com/kennethreitz/requests/tarball/master
After downloading, enter the directory and execute the following command to install:
cd requests python3 setup.py install
After the command is executed, the installation of Requests can be completed. Since this installation method is cumbersome, I won't repeat it later.
5. Verify the installation
In order to verify whether the library has been installed successfully, you can test it in the command line mode:
2 $ python3>>> import requests
First enter python3
, enter the command line mode, and then enter the above content. If there is no error message, it proves that Requests has been successfully installed.