The Python requests library is a powerful tool for simplifying HTTP requests, and is widely used in API calls and network programming. Knowing how to correctly install and update the requests library can help you keep the network functions in your project smooth.

Install Requests

Install using pip

Run the following command to install the latest version of the requests library:

pip install requests

Install a specific version

To install a specific version, you can specify the version number:

pip install requests==<Version Number>

Example:

pip install requests==2.31.0

Install from source

Use git to clone the public repository:

git clone git://github.com/kennethreitz/requests.git

You can also download the source package:

curl -OL https://github.com/requests/requests/tarball/master

After obtaining the source code package, you can directly embed requests into your Python code, or use the pip tool to install it locally;

cd requests
pip install .

Update Requests

Check the current version

Before updating, you can check the current requests version:

pip show requests

Use pip to update

Use the following command to update to the latest version:

pip install --upgrade requests