Home  >  Article  >  Backend Development  >  How to install pip of Python library using domestic mirror source

How to install pip of Python library using domestic mirror source

WBOY
WBOYOriginal
2024-01-17 09:00:061226browse

How to install pip of Python library using domestic mirror source

How to use pip domestic sources to install Python libraries

In the process of using Python to develop, we cannot do without a variety of third-party libraries. To install these libraries, the pip command is usually used. However, when using pip to install libraries in China, we often encounter problems that are slow or even impossible to install. This is because the default pip source is abroad and the access speed is limited. In order to solve this problem, this article will introduce how to use domestic sources to install Python libraries and give specific code examples.

  1. Change pip source

First, we need to switch the pip source to a domestic source. Currently, commonly used pip sources in China include Alibaba Cloud, Tsinghua University, Douban, etc. The following uses Alibaba Cloud as an example to introduce how to set it up.

Enter the following command on the command line to change the pip source to Alibaba Cloud source:

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
  1. Install Python library

Command to install Python library is pip install, followed by the name of the library to be installed. The following is a sample code for installing commonly used libraries:

  • Install numpy library:
pip install numpy
  • Install pandas library:
pip install pandas
  • Install matplotlib library:
pip install matplotlib
  • Install scikit-learn library:
pip install scikit-learn
  1. Update installed libraries

Sometimes, we may want to update installed libraries to get the latest features and bug fixes. At this time, you can use the pip install --upgrade command. The following is a sample code for updating commonly used libraries:

  • Update numpy library:
pip install --upgrade numpy
  • Update pandas library:
pip install --upgrade pandas
  • Update matplotlib library:
pip install --upgrade matplotlib
  • Update scikit-learn library:
pip install --upgrade scikit-learn
  1. Use domestic mirror source to install the library

Sometimes, we need to install some libraries unique to domestic image sources. The following is a sample code for installing the library using Tsinghua University source:

  • Install tensorflow library:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow
  • Install pytorch library:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytorch

Summary:

When using pip to install the Python library in China, you may encounter slow download speeds due to network restrictions. We can change the pip source and switch to the domestic source to improve the installation speed. This article takes Alibaba Cloud as an example to introduce how to change the pip source, install the library, and update the library, and gives specific code examples. I hope this article can help everyone with problems in using pip to install Python libraries in China.

The above is the detailed content of How to install pip of Python library using domestic mirror source. 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