如何通过配置清华镜像源来使用pip进行包的安装?
时间: 2024-10-25 18:09:50 浏览: 61
为了通过配置清华大学的镜像源来使用`pip`进行包的安装,你需要在系统中设置一个合适的`pip`源,特别是在网络访问受限的情况下。以下是Windows、Linux和Mac OS X系统的步骤:
**Windows:**
1. 打开命令提示符(CMD)或PowerShell。
2. 运行以下命令替换`http://pypi.tuna.tsinghua.edu.cn/simple`为你需要的镜像地址,如:`pip config set global.index-url http://pypi.tuna.tsinghua.edu.cn/simple`
3. 如果需要保存这个设置,运行 `pip config set global.trusted-hosts pypi.tuna.tsinghua.edu.cn`
4. 现在你可以使用`pip install package_name`来安装软件了。
**Linux/Mac OS X (使用终端):**
1. 打开终端。
2. 使用文本编辑器(如`nano`, `vim` 或 `TextEdit`),编辑`~/.pip/pip.conf`文件(如果文件不存在,就创建它)。添加或修改`[global]`部分,内容类似于:
```
index-url = http://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
```
3. 保存并关闭文件。
4. 刷新环境变量使其生效:`source ~/.bashrc`(Linux)或`source ~/.zshrc`(macOS 或 ZSH shell)。
现在,当你使用`pip install`命令时,pip会从清华大学镜像源下载软件包。记得每次打开新的shell窗口或终端后执行刷新环境变量的命令。
阅读全文
相关推荐


















