Home  >  Article  >  Backend Development  >  Improve pip mirror source settings and improve Python package update and installation speed

Improve pip mirror source settings and improve Python package update and installation speed

WBOY
WBOYOriginal
2024-01-17 10:01:111067browse

Improve pip mirror source settings and improve Python package update and installation speed

With the wide application of Python in data science, machine learning and other fields, the number of Python packages is also increasing. pip is a Python package manager that can easily download, install and update various packages. Due to domestic network environment restrictions, accessing the official pip source is slow. At this time, it is necessary to optimize the pip mirror source configuration and speed up the update and installation of Python packages.

The following are specific steps and code examples:

  1. Check pip version

Enter the following command in the terminal to check the pip version:

pip --version

If pip has been installed, the following information will be displayed:

pip X.X from /path/to/pip (python X.X)
  1. Configure the pip mirror source

In the ~/.pip/pip.conf file Add the following configuration information:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/ # 清华大学的镜像站

Or the mirror site of Alibaba Cloud:

[global]
index-url = https://mirrors.aliyun.com/pypi/simple/

Enter the following command in the terminal to create the configuration file:

mkdir ~/.pip
touch ~/.pip/pip.conf

Enter the following command to verify the new Check whether the mirror station is working properly:

pip config list

This will list the current pip configuration information to ensure that the new mirror station has been set up successfully.

  1. Update pip

For some reasons, you may need to upgrade the setuptools and wheel packages before updating pip. Enter the following command in the terminal:

pip install --upgrade setuptools
pip install --upgrade wheel

Then you can update pip:

pip install --upgrade pip
  1. Install Python package

Use the optimized pip mirror source , which can speed up the installation of Python packages. Just enter the following command in the terminal:

pip install package_name

Among them, package_name is the name of the Python package that needs to be installed. If the package that needs to be installed depends on other packages, pip will automatically download and install the dependent packages.

  1. List installed packages

Enter the following command in the terminal to list the installed Python packages in the current environment:

pip list
  1. Uninstall Python package

If you need to uninstall an installed Python package, you can enter the following command in the terminal:

pip uninstall package_name

Among them, package_name is the name of the Python package that needs to be uninstalled. .

Summary

By configuring the pip mirror source, you can speed up the update and installation of Python packages. Both Tsinghua University and Alibaba Cloud provide complete pip mirror station services. Users can choose the appropriate mirror source according to their own network environment. When using pip, you can also specify which mirror source to use through command line parameters.

The above is the detailed content of Improve pip mirror source settings and improve Python package update and installation speed. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn