ubuntu切换pip清华源详细过程
时间: 2023-11-17 11:18:05 浏览: 113
切换pip清华源的详细过程如下:
1. 打开终端,输入以下命令安装pip:
```
sudo apt-get update
sudo apt-get install python3-pip
```
2. 输入以下命令备份原有的pip配置文件:
```
cp ~/.pip/pip.conf ~/.pip/pip.conf.bak
```
3. 输入以下命令创建新的pip配置文件并修改为清华源:
```
touch ~/.pip/pip.conf
echo "[global]" >> ~/.pip/pip.conf
echo "index-url = https://pypi.tuna.tsinghua.edu.cn/simple" >> ~/.pip/pip.conf
echo "[install]" >> ~/.pip/pip.conf
echo "trusted-host = pypi.tuna.tsinghua.edu.cn" >> ~/.pip/pip.conf
```
4. 输入以下命令验证是否修改成功:
```
pip config list
```
输出结果中应该包含以下内容:
```
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
```
至此,pip清华源已经成功配置好了。
相关问题
ubuntu中pip换源
### 更改 Pip 源至国内镜像的方法
#### 方法一:临时使用特定源安装包
对于单次操作,可以在命令行中指定 `-i` 参数来使用不同的 PyPI 镜像服务器。例如要安装 `pytest` 可以这样做:
```bash
pip install pytest -i https://pypi.tuna.tsinghua.edu.cn/simple
```
这允许一次性切换到清华大学的PyPI镜像站点进行软件包下载[^1]。
#### 方法二:通过配置文件永久更改Pip源
为了使更改长期生效而不必每次都手动添加参数,可以编辑或创建一个名为 `pip.conf` 的配置文件位于用户的主目录下的隐藏 `.pip` 文件夹里:
```bash
mkdir ~/.pip/
cd ~/.pip/
vim pip.conf
```
接着,在打开后的 `pip.conf` 中加入如下内容以便指向所需的国内镜像站作为默认索引网址并信任该主机:
```ini
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
trusted-host = pypi.tuna.tsinghua.edu.cn
```
上述设置会使得所有的后续pip指令都自动采用清华的镜像服务来进行依赖解析和下载工作[^4]。
另外一种方式是利用 `pip config` 命令直接在终端设定全局变量而无需手工编写配置文档:
```bash
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使用的仓库地址的效果[^3]。
值得注意的是,除了清华大学提供的镜像外还有其他几个常用的国内Python Package Index (PyPI) 镜像可供选择,比如阿里云、豆瓣等平台也提供了类似的加速服务[^2]。
ubuntu切换为清华大学镜像源
你可以按照以下步骤将Ubuntu的pip安装源切换为清华大学镜像源:
1. 打开终端,进入用户主目录。
2. 创建一个名为.pip的隐藏文件夹(如果不存在):
```shell
mkdir ~/.pip
```
3. 创建一个名为pip.conf的文件并编辑它:
```shell
vim ~/.pip/pip.conf
```
4. 在pip.conf文件中,添加以下内容:
```
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple
```
5. 保存并关闭文件。
这样,你的Ubuntu系统就会使用清华大学镜像源作为pip的安装源。
阅读全文
相关推荐















