🌐 常用国内镜像源清单(推荐使用)
推荐首选:清华镜像站或阿里云镜像,更新速度快且稳定性好
快速使用方法
pip install <包名称> -i <镜像URL>
🛠 设置默认镜像源方法
方法一:临时使用镜像源(单次安装)
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple package-name
方法二:命令行永久配置(用户级)
Windows (CMD/PowerShell):
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn
macOS/Linux:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
pip config set global.trusted-host pypi.tuna.tsinghua.edu.cn
🔍 验证配置是否生效
# 查看当前配置
pip config list
# 安装测试包验证速度
pip install -U pip --verbose
不同系统下的最佳实践
- Windows: 建议使用配置文件方式,避免权限问题
- macOS/Linux: 可结合环境变量和全局配置
🔁 恢复默认镜像源
# 方法一:删除配置文件
rm ~/.pip/pip.conf # macOS/Linux
del %APPDATA%\pip\pip.ini # Windows
# 方法二:命令行重置
pip config unset global.index-url
pip config unset global.trusted-host