Home > Backend Development > Python Tutorial > How to modify pip source

How to modify pip source

zbt
Release: 2023-12-05 14:05:08
Original
1476 people have browsed it

Steps to modify the pip source: 1. Open the command prompt or PowerShell and enter the pip config list command; 2. Enter the notepad %APPDATA%\pip\pip.ini command in the command prompt or PowerShell; 3. In the open text file, enter index-url = https://mirrors.aliyun.com/pypi/simple/; 4. Save and close the file.

How to modify pip source

The operating system for this tutorial: Windows 10 system, Python version 3.11.4, DELL G3 computer.

To modify the pip source, you can specify a domestic mirror source, which can help speed up the download speed of Python packages, especially in mainland China. In the next 1500-word answer, I will explain in detail how to modify the pip source.

By default, pip downloads Python packages from https://pypi.org, but due to network reasons, sometimes this source may not be stable enough. Therefore, many users hope to switch the default source of pip to a domestic mirror source, such as Alibaba Cloud, Tsinghua University, etc., to improve the download speed of Python packages. Below I'll explain how to do this on Windows, Mac, and Linux systems.

First, I will introduce how to modify the pip source on Windows system:

1. Open the command prompt or PowerShell and enter the following command to view the current pip source:

pip config list
Copy after login
Copy after login
Copy after login

2. Enter the following command in the command prompt or PowerShell to create or edit the pip configuration file (skip to step 4 if you already have a pip.conf file):

notepad %APPDATA%\pip\pip.ini
Copy after login

3. In the opened text file, enter the following content to specify the mirror source, for example, use the Alibaba Cloud mirror source:

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

You can also use other mirror sources, such as Tsinghua University's mirror source:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Copy after login
Copy after login
Copy after login

4. Save and close the file.

Next, I will introduce how to modify the pip source on the Mac system:

1. Open the terminal and enter the following command to view the current pip source:

pip config list
Copy after login
Copy after login
Copy after login

2. Enter the following command in the terminal to create or edit the pip configuration file (skip to step 4 if you already have a pip.conf file):

nano ~/.pip/pip.conf
Copy after login

3. In the opened text In the file, enter the following content to specify the mirror source, for example, use the Alibaba Cloud mirror source:

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

You can also use other mirror sources, such as Tsinghua University's mirror source:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Copy after login
Copy after login
Copy after login

4. Press Press Ctrl X, then Y, and finally press Enter to save the file.

Finally, I will introduce how to modify the pip source on the Linux system:

1. Open the terminal and enter the following command to view the current pip source:

pip config list
Copy after login
Copy after login
Copy after login

2. Enter the following command in the terminal to create or edit the pip configuration file (skip to step 4 if you already have a pip.conf file):

nano ~/.config/pip/pip.conf
Copy after login

3. In the open text file , enter the following content to specify the mirror source, for example, use the Alibaba Cloud mirror source:

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

You can also use other mirror sources, such as Tsinghua University's mirror source:

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
Copy after login
Copy after login
Copy after login

4. Press Ctrl X, then Y, and finally Enter to save the file.

Through the above steps, you can successfully modify the pip source to a domestic mirror source, thereby increasing the download speed of Python packages.

It should be noted that there may be some problems when using domestic mirror sources. For example, some packages may not exist in domestic mirror sources. Therefore, after switching sources, it is recommended that you be more careful when installing packages to ensure that the required packages can be found in the mirror source.

The above is the detailed content of How to modify pip 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 Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template