pip 设置清华镜像源
时间: 2023-10-27 18:26:58 浏览: 915
在使用pip命令下载Python包时,可以通过设置pip的镜像源为清华镜像来加快下载速度。你可以按照以下步骤设置清华镜像源:
1. 打开终端或命令行窗口。
2. 执行以下命令添加清华镜像源:pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple。
3. 如果你只想对当前用户设置镜像源,可以使用以下命令:pip config set index-url https://pypi.tuna.tsinghua.edu.cn/simple。
除了清华镜像源,你还可以使用阿里云镜像源。如果你想使用阿里云镜像源,可以执行以下命令:pip config set index-url https://mirrors.aliyun.com/pypi/simple/。
通过设置清华镜像源或阿里云镜像源,你可以加快pip下载Python包的速度。<span class="em">1</span><span class="em">2</span><span class="em">3</span><span class="em">4</span>
相关问题
pip设置清华镜像源
可以通过以下步骤将pip设置为清华镜像源:
1. 打开终端或命令行窗口
2. 输入以下命令:
Linux/macOS:
```
pip3 config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
```
Windows:
```
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
```
3. 回车执行命令,等待命令执行完毕即可。
这样就可以使用清华镜像源来加速pip的包下载和更新。
pip 使用清华镜像源
使用清华镜像源可以显著提高在国内环境中通过 `pip` 安装 Python 包的速度和稳定性。清华大学开源软件镜像站 (TUNA) 提供了包括 PyPI 在内的多种常用资源的镜像服务。
### 设置临时使用清华镜像源
如果你只是想临时一次使用清华镜像源来安装某个特定包,可以在命令行中直接指定 `-i` 参数加上清华镜像地址:
```bash
pip install <package_name> -i https://pypi.tuna.tsinghua.edu.cn/simple
```
例如,要安装 `numpy` 这个库,则输入:
```bash
pip install numpy -i https://pypi.tuna.tsinghua.edu.cn/simple
```
### 永久配置清华镜像源
若希望所有 `pip` 安装操作都默认从清华镜像源获取数据,可以通过修改或创建 `~/.pip/pip.conf` 文件(Linux/MacOS 下)或者 `%APPDATA%\pip\pip.ini` 文件(Windows 下),添加以下内容:
#### Linux / MacOS (`~/.pip/pip.conf`)
```ini
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
```
#### Windows (`%APPDATA%\pip\pip.ini`)
```ini
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
```
此外,在某些情况下你还可以选择设置环境变量的方式代替文件配置:
```sh
export PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
# 对于 Windows 用户应改为:
set PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple
```
### 更换回官方源
如果之后需要恢复成使用官方 PyPI 源,默认只需要删除上述配置即可;也可以手动指定为官方源:
```bash
pip config set global.index-url https://pypi.org/simple/
```
这样做可以让所有的后续安装请求指向原始的PyPI仓库。
阅读全文
相关推荐















