升级最新pip版本

总所周知,在国内下载python依赖包,因为网络原因,非常慢或者无法下载。下面提供两种使用国内镜像的下载方式

python -m pip install --upgrade pip

出现类似以下提示表示升级成功可能用户在安装时会比pip-23.2.1的版本更高。

Installing collected packages: pip
  Attempting uninstall: pip
    Found existing installation: pip 22.3.1
    Uninstalling pip-22.3.1:
      Successfully uninstalled pip-22.3.1
Successfully installed pip-23.2.1

国内镜像

阿里http://mirrors.aliyun.com/pypi/simple/
清华大学 https://pypi.tuna.tsinghua.edu.cn/simple/
中国科技大学 https://pypi.mirrors.ustc.edu.cn/simple/
豆瓣 http://pypi.douban.com/simple
Python官方 https://pypi.python.org/simple/
v2ex http://pypi.v2ex.com/simple/
中国科学院 http://pypi.mirrors.opencas.cn/simple/
中国科学技术大学 [http://pypi.mirrors.ustc.edu.cn/simple/
华中理工大学http://pypi.hustunique.com/
山东理工大学http://pypi.sdutlinux.org/

阿里镜像源较为稳定可以长期使用。如果不设置镜像源,默认采用的时Python官方镜像源,官方镜像国内下载较慢或者无法下载。其他镜像源也均可选择参考文献

单次安装使用国内镜像源

单次安装某一依赖包,可使用以下命令,本处以阿里云镜像安装为例。本次安装依赖包为tensorflow,未指定版本时,会安装目前最新依赖版本例如

pip install tensorflow -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

指定版本可以使用命令如下

pip install tensorflow==2.13.0 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com

永久设置国内镜像源

以设置阿里云镜像为例

pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/
pip config set global.trusted-host mirrors.aliyun.com

综上,使用国内镜像源可以大幅度加速下载。同时在设置镜像源时,要同时设置indexurl和trustedhost,否则还是显示报错

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注