1.安装opencv-python失败的解决办法 2.pip 安装失败 3.WARNING:Ignoring invalid distribution-ip 的解决办法 +镜像网站

问题:安装opencv-python失败:

用:

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

安装会被卡在
Building wheel for opencv-python (pyproject.toml) ... 之后便安装失败。


使用顺序:先使用方法二,再使用方法一(有可能不会解决问题),用方法三查看问题出现在哪个地方。


方法一.更新pip,setuptools,wheel,再重新安装

语法:pip install --upgrade pip setuptools wheel
参考文章:安装opencv-python失败报错解决方案

但是在pip install --upgrade pip setuptools wheel 之后,pip就没了 ,显示如下:

Script file 'G:\2E\anaconda\envs\pytorch\Scripts\pip-script.py' is not present.

原因是 在使用 pip install --ugrade pip 命令升级的时候,会先将原来的 pip 卸载掉再安装新版本的 pip,但是在成功卸载之后,由于权限的问题无法安装新版本 pip ,所以 pip 就没法使用了。

于是为了解决pip消失的问题,
从源码重新安装 pip 即可,使用以下方法来安装:

$ curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py   # 下载安装脚本
$ python get-pip.py    # 运行安装脚本

参考文章:Anaconda\Scripts\pip-script.py is not present ? 解决方法

curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
安装过程中,显示
This script does not work on Python 3.6 The minimum supported Python version is 3.7. Please use https://bootstrap.pypa.io/pip/3.6/get-pip.py instead.

在这里插入图片描述
所以需要改一下,
curl https://bootstrap.pypa.io/pip/3.6/get-pip.py -o get-pip.py 即可,再 python get-pip.py ,安装成功。

后来又由于 可能是之前下载库的时候没有成功或者中途退出。 出现警告

在这里插入图片描述

解决方法就是,删除掉带~的文件夹:

在这里插入图片描述

再执行pip的命令,已经没有了黄色的告警。

在这里插入图片描述

参考文章:python使用 pip 命令时提示“WARNING: Ignoring invalid distribution -ip”的解决方案

但是 使用最新版本的wheel,setuptools,pip, 还是和之前一样的结果安装不上,opencv-python。

另外,中间还出现过问题,
AttributeError: module 'distutils' has no attribute 'version'
解决办法:Python AttributeError: module ‘distutils‘ has no attribute ‘version‘


方法二.寻找适合的opencv-python版本进行安装

安装失败可能的原因:是版本不兼容的问题,当使用pip install opencv-python命令 安装的是最新版本,当前python版本不支持。需要安装当前版本python支持的opencv-python版本。

查看镜像网站的opencv-python版本:
https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple/opencv-python/

其实,只能我也不知道哪个版本兼容哪个,那么真相只有一个!挨个试一下!
语法:
pip install opencv-python==4.3.0.38 -i https://pypi.tuna.tsinghua.edu.cn/simple

先使用上面的版本试一下,之后再多跳几个版本试一下,如果再失败就换其他方法
在这里插入图片描述

参考文章:
1.pip下载包opencv出错(报错failed building wheel for opencv-python解决方法)
2.python安装opencv报错ERROR: Could not build wheels for opencv-python, which is required to install…
3.虚拟环境安装opencv失败,卡在Building wheel for opencv-python (pyproject.toml) … error

方法三.使用 --verbose 参数

使用–verbose 参数之后,安装过程会有进度条,根据安装的细节(进度条),找到是哪里安装失败,并针对性解决!
参考文章:
1.Building wheel for opencv-python (pyproject.toml) ,安装命令增加 --verbose 参数
2.opencv安装报错解决方案

四.一些镜像网站

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

语法:pip  install -i https://pypi.tuna.tsinghua.edu.cn/simple opencv-python
替换对应网址即可

参考文章:
1.pip install 遇到‘time out’问题解决办法
2.安装opencv-python(有永久修改源的方法)

写于2024.5.30 15:22:53

  • 31
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值