本文共 1975 字,大约阅读时间需要 6 分钟。
代码里cv2标红了,发现需要安装opencv,于是开始了。。。。
一开始查到说安装cv2模块,不能直接用命令pip install cv2安装,要用命令如下:
pip install opencv-python
使用命令后报错如下:
ERROR: Exception:
Traceback (most recent call last): File “/Users/xxx/opt/anaconda3/lib/python3.8/site-packages/pip/_vendor/resolvelib/resolvers.py”, line 171, in _merge_into_criterion crit = self.state.criteria[name] KeyError: ‘opencv-python’ During handling of the above exception, another exception occurred: Traceback (most recent call last): File “/Users/xxx/opt/anaconda3/lib/python3.8/site-packages/pip/_vendor/urllib3/response.py”, line 438, in _error_catcher
发现是网速太慢,换了镜像网址,命令如下:
pip install opencv-python -i https://pypi.tuna.tsinghua.edu.cn/simple
更换镜像网址后出现最致命的错误:
ERROR: Could not find a version that satisfies the requirement opencv-python
ERROR: No matching distribution found for opencv-python
后来发现是opencv没有osx系统对应的包
解决办法:使用anaconda集成集成发现anaconde的镜像网址全部被墙了(没有)
解决办法:安装homebrew安装好了,开始安装opencv
使用命令:brew install opencv
报错:
curl: (22) The requested URL returned error: 404 Not Found
Error: Failed to download resource “eigen”
但同时终端回显示下载失败文件的下载网址:
Download failed: https://storage.googleapis.com/dart-archive/channels/stable/release/2.7.2/sdk/dartsdk-macos-x64-release.zip
之后我们就可以用自己浏览器或者下载器下载需要的文件。
之后使用终端查看Homebrew的缓存地址:brew --cache
打印出以下地址:
/Users//Library/Caches/Homebrew
最后将下载下来的文件拷贝到缓存地址:cp ~/Downloads/dartsdk-macos-x64-release.zip /Users/xxx/Library/Caches/Homebrew
最后使用Homebrew安装,这个时候就可以成功了。
但是问题来了,我的文件网址url"https://github.com/opencv/opencv/archive/4.5.2.tar.gz"
网址打不开,此方法行不通。。。。之后发现,在bilibli看到一遍文章,网址如下,https://www.bilibili.com/read/cv9542204
anaconda绝了! 步骤: 1. 打开Anaconda,点击步骤:Environment > Create > Python3.x > 输入name > Create 2. 勾选All,点击Update Index…。搜索出opencv并勾选。Apply。 3.在name中的终端输入命令,没报错即可python
import cv2
打开pycharm中的项目,点开preferences > project:xxx > python interpreter,点击其右锯齿,选择Add。左边选择Conda Environment,右边点击existing environment,然后再文件路径中选择对应的python文件,例如/Users/xxx/opt/anaconda3/envs/tensorflow/bin/python
然后代码里的cv2就不标红了,ok
转载地址:http://lnoen.baihongyu.com/