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.
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/
Command to install Python library ispip install
, followed by the name of the library to be installed. The following is a sample code for installing commonly used libraries:
pip install numpy
pip install pandas
pip install matplotlib
pip install scikit-learn
Sometimes, we may want to update installed libraries to get the latest features and bug fixes. At this time, you can use thepip install --upgrade
command. The following is a sample code for updating commonly used libraries:
pip install --upgrade numpy
pip install --upgrade pandas
pip install --upgrade matplotlib
pip install --upgrade scikit-learn
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:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple tensorflow
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!