The method to solve other error reports such as pip download speed is too slow and timeout is suitable for various operating systems (details)

Table of contents

Preface

1. Common domestic sources

2. Setting method (taking Doubanyuan as an example)

1. Temporary use

2. Permanent settings

windows operating system:

Linux operating system:

Mac operating system:

3. Solve other problems

1. The mirror source is permanently set but the download speed does not change.

2. ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied.

3. Incompatibility issues (general method)

4. Summary


​​​​​​​

Preface

As an excellent Python programmer, you must deal with pip. Friends who have used the pip download library must know that its download speed cannot be described as slow, mainly because pip uses foreign sources by default. Therefore, the download speed will be slow. Of course, this is also related to the mood of the network in some areas and the pip official mirror source server. The most direct solution is to replace it with a domestic download source.


1. Common domestic sources

1. Tsinghua University: https://pypi.tuna.tsinghua.edu.cn/simple/      (commonly used)

2. Douban: https://pypi.douban.com/simple/

3. Aliyun: https://mirrors.aliyun.com/pypi/simple/

4.中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/

Personally, I recommend Doubanyuan


2. Setting method (taking Doubanyuan as an example)

1. Temporary use

For example, if you want to download the pygame library, you can use the following method to set the temporary domestic source:

pip install pygame -i https://pypi.douban.com/simple/

General setting temporary mirror source method -i: Indicates temporarily using the current mirror source
pip install 安装包 -i 国内源

2. Permanent settings

windows operating system:

Be sure to upgrade pip to the latest version (-U means to upgrade the installed installation package to the latest version):

python -m pip install pip -U -i https://pypi.douban.com/simple/

Configure permanent domestic sources (for all the following operating systems) 

pip config set global.index-url https://pypi.douban.com/simple/

After entering the previous line of command, you can directly see the file written to the configuration source or win+r and enter %APPDATA% in the pop-up window, then find the pip folder and click on it to see the pip.ini configuration file (only suitable for windows operating system).

 Note: You can enter pip config list to view the currently configured domestic source, if you want to modify it back to the original source, just delete the pip folder.

Then open the pip.ini file and enter the following:

[global] 
index-url=https://pypi.douban.com/simple/ 
[install]
trusted-host=pypi.douban.com

Linux operating system:

Method 1: Use the Windows operating system to configure permanent domestic sources (be sure to upgrade pip first) 

Method two: as follows

First edit the pip.conf file under the pip folder in the current user's home directory (if not, create a new one)

vim ~/.pip/pip.conf 

Then add the following content, then save and exit.

[global] 
index-url=https://pypi.douban.com/simple/ 
[install]
trusted-host=pypi.douban.com

Mac operating system:

sudo vim ~/.pip/pip.conf
to save, press esc and then enter: wq and press Enter to take effect.

[global]
index-url=https://pypi.douban.com/simple/
disable-pip-version-check = True //忽略pip升级提示
[install]
trusted-host=pypi.douban.com

 If there is no such file for the first time, you need to create the file first, and then edit the above configuration

mkdir .pip
touch pip.conf
vim pip.conf


3. Solve other problems

1. The mirror source is permanently set but the download speed does not change.

After pip.ini or pip.conf is configured, but the download still times out or the download is slow, you can change the original content (applicable to all the above systems):

[global]

index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com

;index-url = https://pypi.tuna.tsinghua.edu.cn/simple
;trusted-host = pypi.tuna.tsinghua.edu.cn

timeout = 6000

2. ERROR: Could not install packages due to an OSError: [WinError 5] Access is denied.

Solution 1: pip install XXXChange it pip install --user XXXto

Solution 2 : The most terrible situation is that when you use pip install pip -U to upgrade pip, it will delete the old pip library and then report an error denying access. As a result, when you use pip again, you will get the error that there is no pip library:

Traceback (most recent call last):
  File "d:\python\lib\runpy.py", line 197, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "d:\python\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "D:\Python\Scripts\pip.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'pip'

For Xiaobai, this problem is really broken (personal experience)

You can reinstall pip by entering the following command:

python -m ensurepip

You can enter the following command to upgrade pip:

python -m pip install --upgrade pip

 

3. Incompatibility issues (general method)

If you have tried all methods but the error message does not change, it may be that this python version is not compatible with the libraries, so you can only change the python interpreter and then re-download the required libraries.


4. Summary

Thank you all for watching. If the article is helpful to you, please give it a like or follow it and preferably also give it a reward⁄(⁄ ⁄•⁄ω⁄•⁄ ⁄)⁄. Your support is my biggest motivation for updating!

Reference article:

https://blog.csdn.net/weixin_45005677/article/details/120590496

https://blog.csdn.net/qq_33605607/article/details/101602642

https://blog.csdn.net/qq_34663531/article/details/123782720

Guess you like

Origin blog.csdn.net/python_sy/article/details/126710868