配置Python的国内镜像源可以通过以下几种方法:
临时使用国内镜像源
如果你只是想要临时使用国内镜像源来安装某个库,可以使用`-i`参数指定镜像地址:
pip install some-package -i https://pypi.tuna.tsinghua.edu.cn/simple/
将`some-package`替换为你想要安装的包名。
永久修改配置文件
如果你希望每次使用`pip`时都使用国内镜像源,可以修改`pip`的配置文件。
对于Windows系统:
1. 在`C:\Users\[用户名]\pip`目录下创建`pip.ini`文件(如果不存在)。
2. 编辑`pip.ini`文件,添加以下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
对于Linux系统:
1. 在`~/.pip`目录下创建`pip.conf`文件(如果不存在)。
2. 编辑`pip.conf`文件,添加以下内容:
[global]
index-url = https://pypi.tuna.tsinghua.edu.cn/simple/
[install]
trusted-host = pypi.tuna.tsinghua.edu.cn
使用`pip config`命令
你也可以使用`pip config`命令来设置默认镜像源:
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple/
其他国内镜像源
除了清华大学的镜像源,还有如下一些常用的国内镜像源:
阿里云镜像源:[https://mirrors.aliyun.com/pypi/simple/](https://mirrors.aliyun.com/pypi/simple/)
中国科学技术大学镜像源:[https://mirrors.ustc.edu.cn/](https://mirrors.ustc.edu.cn/)
上海交通大学镜像源:[https://mirror.sjtu.edu.cn/](https://mirror.sjtu.edu.cn/)
豆瓣镜像源:[http://pypi.douban.com/simple/](http://pypi.douban.com/simple/)