【python入门之pip换源问题】---pip换源的方式

【一】PIP更换源包

【1】问题描述

在使用Python时,我们经常需要用到pip安装第三方包。

但是,在某些情况下,由于网络速度慢或者其他各种原因,pip install会非常慢,甚至可能无法完成。

为了解决这个问题,我们提供以下几种方法。

「 解决方法」

【第一种】永久更换pip源

一般来说,默认使用的pip源都会因为各种原因会变得缓慢,因此可以将pip源改为国内较快的源来提升下载速度。
  • 打开控制台或终端(cmd shell),并输入以下命令:
pip config set global.index-url https://mirrors.aliyun.com/pypi/simple/
  • 更改pip源后,可以通过以下命令验证:
pip config get global.index-url
  • 注:如果返回值为https://mirrors.aliyun.com/pypi/simple/,则表示更改成功。

【第二种】临时使用pip源

  • 输入pip install xxx时插入国内镜像源地址,变为pip install -i 地址 xxx并回车。

  • 假设我们需要安装名为opencv-python的Python包。

  • 使用默认源安装opencv-python

pip install opencv-python
  • 使用清华大学镜像源,重新安装opencv-python
pip install -i https://pypi.tuna.tsinghua.edu.cn/simple/ opencv-python

【2】常用的镜像源

清华大学:	   https://pypi.tuna.tsinghua.edu.cn/simple/
阿 里 云:	  https://mirrors.aliyun.com/pypi/simple/
豆    瓣:	   https://pypi.douban.com/simple/
中 科 大:	  https://pypi.mirrors.ustc.edu.cn/simple/
posted @ 2023-11-27 20:10  Unfool  阅读(167)  评论(0)    收藏  举报