This document was created on March 9, 2023
This article records the operation of pip changing the source and changing the default installation location. It is mainly used for some configurations of pip, which is convenient for downloading and file management
pip change source
When using pip to install the library, if you use the default library, you often encounter the problem of being unable to connect or downloading slowly. It will be faster to download it if you replace it with a domestic library.
Temporary source change
Add after the installation command -i url
, for example:
pip install PyQt6 -i https://pypi.tuna.tsinghua.edu.cn.simple/
permanent replacement
Use the pip command to set the pip domestic source:
#先更新一下pip版本
python -m pip install pip -U #-i https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
pip config set install.trusted-host https://pypi.tuna.tsinghua.edu.cn
Change pip default installation location
When using pip under windows, the default installation location is the C drive. In order not to take up space on the C drive, we can modify the default installation location.
Open the terminal and check the current installation location first:
python -m site
USER_BASE and USER_SITE show the current installation location
Find files that hold USER_BASE and USER_SITE:
python -m site -help
Open the site.py file shown:
Modify USER_BASE and USER_SITE:
USER_SITE = "D:\software\\anaconda3\Lib\site-packages"
USER_BASE = "D:\software\\anaconda3\Scripts"
After saving, open the terminal again, enter python -m site
, and the displayed USER_BASE and USER_SITE have changed, and the modification is successful:
It should be noted that after modifying the default installation location, the following error may appear when installing the package:
ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: ‘d:\software\visualstudioshared\python39_64\lib\site-packages\pip-22.3.1.dist-info\entry_points.txt’ Check the permissions.
s\pip-22.3.1.dist-info\entry_points.txt’ Check the permissions.
This is because the installation is not successful due to insufficient access rights, just run cmd (PowerShell) as an administrator.