阡陌 发表于 2024-3-28 15:27:51

修改 pip 源为国内镜像源


由于网络原因,直接使用 pip 默认源会很慢得可怕,这里提供一些国内的镜像,你可以选择使用:

1. 阿里云:https://mirrors.aliyun.com/pypi/simple/
2. 中国科技大学:https://pypi.mirrors.ustc.edu.cn/simple/
3. 豆瓣(douban):http://pypi.douban.com/simple/
4. 清华大学:https://pypi.tuna.tsinghua.edu.cn/simple/
5. 中国科学技术大学:https://pypi.mirrors.ustc.edu.cn/simple/



你可以在使用 pip 时通过 `-i` 参数指定使用上述源:

```bash
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple some-package
```



如果想要永久修改,可以在 pip 配置文件中设置。配置文件位置和名称取决于操作系统:

- Linux/Unix: `~/.pip/pip.conf`
- Windows: `%APPDATA%\pip\pip.ini`(`%APPDATA%` 指 `C:\Users\用户名\AppData\Roaming`)

若文件不存在,则需手动创建。

配置文件内容如下:

```ini

index-url = https://pypi.tuna.tsinghua.edu.cn/simple
```

对于使用 http 的源,可以选择性地加上 trusted-host 以信任它,避免出现警告信息。例如:

```ini

index-url = http://pypi.douban.com/simple
trusted-host = pypi.douban.com
```

这样配置后,你每次使用 pip 安装包时都会默认使用这个源。


页: [1]
查看完整版本: 修改 pip 源为国内镜像源