ubuntu pip国内源
时间: 2024-10-18 18:01:32 浏览: 54
Ubuntu 系统中通常使用的是Python的包管理工具pip,如果你在中国并希望使用国内的源来加速软件包的下载,可以更换为中国镜像源。以下是设置国内pip源的步骤:
1. **使用阿里云PyPI源**:
打开终端,运行以下命令(需要有root权限):
```
sudo apt-get install software-properties-common python-software-properties
curl https://mirrors.aliyun.com/pypi/simple/install.sh | sh
```
完成后,更新pip源列表:
```
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
```
2. **使用清华大学源**:
类似地,添加清华源:
```
sudo add-apt-repository ppa:mirrors-list/ppa && sudo apt-get update
pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
```
记得每次安装新包时,pip会从你配置的源获取。
相关问题
ubuntu更换pip国内源
### 配置 Pip 使用国内镜像源
#### 方法一:通过命令行临时指定镜像源
对于单次安装操作,可以在命令行中直接指定国内镜像源来加速下载速度:
```bash
pip install [包名] -i [镜像源URL]
```
例如,要使用清华大学的镜像源安装 `pytest` 可以执行如下命令[^2]:
```bash
pip install pytest -i https://pypi.tuna.tsinghua.edu.cn/simple
```
#### 方法二:修改全局配置文件实现永久更改
为了使每次调用 pip 安装软件包都自动使用国内镜像源,在用户的主目录下创建或编辑 `.pip/pip.conf` 文件。
如果该路径不存在,则需先建立相应目录并新建此文件:
```bash
mkdir -p ~/.pip/
cd ~/.pip/
vim pip.conf
```
接着向其中添加以下内容之一,取决于想要使用的具体镜像站[^3]:
- **阿里云**
```ini
[global]
index-url=https://mirrors.aliyun.com/pypi/simple/
```
- **豆瓣**
```ini
[global]
index-url=https://pypi.douban.com/simple/
```
- **清华大学**
```ini
[global]
index-url=https://pypi.tuna.tsinghua.edu.cn/simple/
```
- **中国科学技术大学**
```ini
[global]
index-url=https://pypi.mirrors.ustc.edu.cn/simple/
```
- **华中科技大学**
```ini
[global]
index-url=https://pypi.hustunique.com/
```
完成上述任一步骤之后保存退出即可生效。这样以后再运行任何涉及 pip 的指令都会默认采用所选中的国内镜像源了[^1]。
ubuntu pip 换源
要更改Ubuntu中pip的源,你可以按照以下步骤进行操作:
1. 首先,打开终端。你可以使用快捷键Ctrl+Alt+T来打开终端。
2. 执行以下命令来编辑pip的配置文件:
```
sudo nano /etc/pip.conf
```
如果提示你输入密码,请输入你的管理员密码并按Enter键。
3. 在打开的编辑器中,将以下内容粘贴到文件中:
```
<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [[Ubuntu18.04][Python][pip][国内源]Ubuntu系统的pip安装与配置国内源](https://download.csdn.net/download/weixin_38600696/14037193)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [ubuntu 更换系统软件源 和 pip源](https://blog.csdn.net/weixin_39715012/article/details/120635192)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文
相关推荐
















