转到国内地址下载

211 阅读1分钟

在 python 里经常要安装各种第三方模块,以 pandas 模块为例,在 CMD 窗口中输入以下命令进行安装:

pip install pandas 默认是从国外服务器下载模块,速度比较慢,可以使用 -i 参数临时将 pip 源换成国内源,如:

pip install pandas -i pypi.tuna.tsinghua.edu.cn/simple 常见的国内 pip 源有以下几种,大家根据需要选用:

pypi 清华大学源:pypi.tuna.tsinghua.edu.cn/simple

pypi 豆瓣源 :pypi.douban.com/simple/

pypi 腾讯源:mirrors.cloud.tencent.com/pypi/simple

pypi 阿里源:mirrors.aliyun.com/pypi/simple…

临时修改源需要每次输入一长串网址,非常不便,可以把国内源设为默认:

清华源

pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

阿里源

pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/

腾讯源

pip config set global.index-url http://mirrors.cloud.tencent.com/pypi/simple

豆瓣源

pip config set global.index-url http://pypi.douban.com/simple/

设置后使用 pip install 命令安装模块时就不用使用 -i 参数了。