修改 pip 镜像源和包安装路径, 并添加环境变量

1、修改清华镜像源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

2、修改包安装地址和缓存

在路径`C:\Users\Administrator\AppData\Roaming\pip\pip.ini`中

常用镜像源


镜像源	URL
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple(推荐)
阿里云	https://mirrors.aliyun.com/pypi/simple/
腾讯云	https://mirrors.cloud.tencent.com/pypi/simple
华为云	https://repo.huaweicloud.com/repository/pypi/simple
豆瓣	https://pypi.douban.com/simple/
中科大	https://pypi.mirrors.ustc.edu.cn/simple/

 

[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
cache-dir = D:\dev\dev-tools\pip_cache
timeout = 6000

[install]
prefix = D:\dev\dev-tools\pip_install

3、设置系统环境变量

PIP_CACHE_DIR = D:\dev\dev-tools\pip_cache

PYTHONUSERBASE = D:\dev\dev-tools\pip_install(用户级安装目录)

4、最后

# 查看所有配置
pip config list

# 查看缓存 
pip cache dir 

# 查看具体配置项
pip config get global.index-url

# 查看缓存大小
pip cache info

# 清理所有缓存
pip cache purge

# 清理指定包的缓存
pip cache remove 包名