方法1:编辑pip.ini文件
首先确定pip的位置,在命令提示符下运行:
C:\Users\ljm>where pip
我这里有这样的3条记录:
C:\Users\ljm\AppData\Local\Continuum\anaconda3\Scripts\pip.exe
C:\Python27\Scripts\pip.exe
C:\Users\ljm\AppData\Local\Programs\Python\Python37\Scripts\pip.exe
想给哪个pip更改源,就在哪条记录中与Scripts同一级创建一个pip.ini文件。
比如我要给anaconda环境下更改源,就创建一个这样的pip.ini文件:
C:\Users\ljm\AppData\Local\Continuum\anaconda3\pip.ini
文件内容:
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host = https://mirrors.aliyun.com
方法2:使用命令
电脑重装之后,我发现上面的办法不好用了,于是又找了一个方法,来源于阿里巴巴镜像库的评论区:
https://developer.aliyun.com/mirror/pypi?spm=5176.12901015.0.i12901015.52b3525chtTSfh
在相应的环境中运行:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/