Friends who often play with AI tools, especially open-source tools, inevitably encounter situations where Python needs to be deployed locally. Then you will probably encounter many pip-related errors. For example, when installing with pip install xxx
, the speed is very slow, a few kb/s. For models that are several GB in size, it will take forever to download.
Sometimes it cannot be downloaded directly, and the prompt is cannot connect huggingface.co
. After finally configuring a scientific internet environment, another error occurs, with proxyError
, max retries
and other errors emerging one after another.
Now let's briefly deal with these problems.
1. Slow download speed
The pip download source is abroad. As we all know, for various reasons, domestic downloads will inevitably be very slow.
Temporarily use the Aliyun mirror
If you are only installing one module, or using it occasionally, you can specify to use the Aliyun mirror after the command, as follows:
pip install xx模块名 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
Permanently change to Aliyun mirror
If you use it frequently, the temporary method is very inconvenient. At this time, on Windows, open [Computer] --> [C drive] --> [Users] --> [Your username] --> [pip folder (create it if it does not exist)]. Open the pip.ini
file inside. Similarly, if this file does not exist, create it. Note that the suffix extension is .ini
instead of .txt
.
Then clear the contents and replace them with:
[global]
index-url = http://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
What if I want to use other mirror sources? Such as Tsinghua University, etc.? The method is the same, the only difference is
index-url
andtrusted-host
. Replace them according to the provided method.
# Douban:
[global]
index-url = https://pypi.douban.com/simple/
[install]
trusted-host=pypi.douban.com
# Tsinghua University:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host=pypi.tuna.tsinghua.edu.cn
# University of Science and Technology of China:
[global]
index-url = https://pypi.mirrors.ustc.edu.cn/simple/
[install]
trusted-host=pypi.mirrors.ustc.edu.cn
2. I have already used a domestic mirror, but I still get a bunch of errors?
Check carefully whether there are proxyError
or Retrying (Retry(total=4
errors in the error, as shown in the figure:
Domestic mirrors are not allowed to use foreign IPs for downloading. If this error occurs, please turn off the proxy, or reverse the operation according to the above method and delete pip.ini
to use the official default pip source.
3. A bunch of red errors, with many version number digits
As shown in the following error:
This error indicates that the version you specified does not exist. Only the version numbers after from versions:
can be installed. At this time, you can find a version that is closest to the version number you specified, and the first version number digit is the same to install.
For example, pip install requests==2.32.0
, want to install this version, but it does not exist. As observed in the figure above, starting with version 2.
, and the closest version number is 2.32.2
, then the command can be changed to pip install requests==2.32.2
.
You may also encounter other problems, especially module conflicts. For example, two modules a and b both need to use module c, but a needs version 1.2 of c, but b needs version 3.6 of c, which causes a conflict. Which one to choose specifically depends on the situation.