How to install pip of Python library using domestic mirror source

WBOY
Release: 2024-01-17 09:00:06
Original
1132 people have browsed it

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/
Copy after login
  1. Install Python library

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:

  • Install numpy library:
pip install numpy
Copy after login
  • Install pandas library:
pip install pandas
Copy after login
  • Install matplotlib library:
pip install matplotlib
Copy after login
  • Install scikit-learn library:
pip install scikit-learn
Copy after login
  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 thepip install --upgradecommand. The following is a sample code for updating commonly used libraries:

  • Update numpy library:
pip install --upgrade numpy
Copy after login
  • Update pandas library:
pip install --upgrade pandas
Copy after login
  • Update matplotlib library:
pip install --upgrade matplotlib
Copy after login
  • Update scikit-learn library:
pip install --upgrade scikit-learn
Copy after login
  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
Copy after login
  • Install pytorch library:
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pytorch
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!