python配置国内pip源

发现问题:

你安装了python,但是通过pip下载包很慢。
例如:你要下载pandas、numpy等较大的包,但是下载很慢,等了好久竟然超时了。


原因分析:

安装了官方pip后,默认配置的是国外的pip库,因此下载就会很慢。


解决方案:

配置国内的pip源,个人习惯清华大学的pip源。强烈建议使用这种命令行的方式,经过笔者试验,linux/windows均使用。完美了!

常用的国内pip源:
https://pypi.tuna.tsinghua.edu.cn/simple
http://mirrors.aliyun.com/pypi/simple/
http://pypi.douban.com/simple/

国内常用的开源软件镜像站点:
https://mirrors.tuna.tsinghua.edu.cn/help/pypi/

临时使用

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

设为默认

step1:升级pip版本

pip install -i https://pypi.tuna.tsinghua.edu.cn/simple pip -U

step2: 设置默认pip源

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

如果本地配置了多个python,只想给某个python升级,你只要python -m pip xxxx就行了。

step3:开始使用pip

D:\cmder
λ C:\Python38\python.exe -m pip install --upgrade pip
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Collecting pip
  Downloading https://pypi.tuna.tsinghua.edu.cn/packages/fe/ef/60d7ba03b5c442309ef42e7d69959f73aacccd0d86008362a681c4698e83/pip-21.0.1-py3-none-any.whl (1.5 MB)
     |████████████████████████████████| 1.5 MB 327 kB/s
Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 20.2.3
    Uninstalling pip-20.2.3:
      Successfully uninstalled pip-20.2.3
Successfully installed pip-21.0.1

D:\cmder
λ C:\Python38\python.exe -m pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
Writing to C:\Users\robin\AppData\Roaming\pip\pip.ini

D:\cmder
λ pip --version
pip 21.0.1 from c:\python38\lib\site-packages\pip (python 3.8)

D:\cmder
λ pip install pandas
Looking in indexes: https://pypi.tuna.tsinghua.edu.cn/simple
Requirement already satisfied: pandas in c:\python38\lib\site-packages (1.2.3)
Requirement already satisfied: python-dateutil>=2.7.3 in c:\python38\lib\site-packages (from pandas) (2.8.1)
Requirement already satisfied: pytz>=2017.3 in c:\python38\lib\site-packages (from pandas) (2021.1)
Requirement already satisfied: numpy>=1.16.5 in c:\python38\lib\site-packages (from pandas) (1.20.2)
Requirement already satisfied: six>=1.5 in c:\python38\lib\site-packages (from python-dateutil>=2.7.3->pandas)
上一篇:pip更新源以及虚拟环境安装


下一篇:pip安装第三方库