python安装包国内镜像源步骤
时间: 2024-10-08 09:25:33 浏览: 207
在Python中安装包时使用国内镜像源可以加快下载速度,特别是对于网络环境不佳的情况。以下是通过pip(Python包管理器)设置阿里云或清华大学镜像源的基本步骤:
1. **配置pip源**:
打开命令行终端,首先需要更新pip到最新版本(如果已安装旧版):
```
pip install --upgrade pip
```
2. **添加镜像源**:
使用`pip config set global.index-url`命令添加国内镜像源,例如阿里云的PyPI源(https://mirrors.aliyun.com/pypi/simple/):
```
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
```
或者清华大学源(http://pypi.tuna.tsinghua.edu.cn/simple/):
```
pip config set global.index-url http://pypi.tuna.tsinghua.edu.cn/simple/
```
确认添加成功后,可以查看当前镜像源:
```
pip config get global.index-url
```
3. **验证镜像是否有效**:
安装某个库试试看,如 `pip install requests`。如果速度快,说明镜像源已经生效。
4. **强制使用镜像**:
如果想每次安装都从镜像源获取,可以在pip命令前加上`--index-url`选项,比如:
```
pip install --index-url https://mirrors.aliyun.com/pypi/simple/ requests
```
阅读全文
相关推荐


















