python - 每当使用 import cv2 时,OpenCV 都会出错
问题描述
我在终端上使用 pip3 install opencv-contrib-python 安装了 cv2 并且它可以工作,但是在 python IDLE 上,每当我尝试导入 cv2 或运行导入了 cv2 的 vscode 文件时,它都会说
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/__init__.py", line 3, in <module>
from .cv2 import *
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/cv2.cpython-38-darwin.so, 2): Symbol not found: _inflateValidate
Referenced from: /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/.dylibs/libpng16.16.dylib (which was built for Mac OS X 10.13)
Expected in: /usr/lib/libz.1.dylib
in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/cv2/.dylibs/libpng16.16.dylib
在终端。知道如何解决这个问题吗?
解决方案
I had the same question and I found it's because I use a high version of opencv (4.X.X), and my system version is low (mac os 10.12.5). So I installed a lower version of opencv (3.4.5.20), and then the question is solved.
You can use the following command to list the versions of opencv:
pip install opencv-python==
ERROR: Could not find a version that satisfies the requirement opencv-python== (from versions: 3.4.2.16, 3.4.2.17, 3.4.3.18, 3.4.4.19, 3.4.5.20, 3.4.6.27, 3.4.7.28, 3.4.8.29, 3.4.9.31, 4.0.0.21, 4.0.1.24, 4.1.0.25, 4.1.1.26, 4.1.2.30, 4.2.0.32) ERROR: No matching distribution found for opencv-python==
Then you can try a lower version (3.4.5.20, for example), and install it using:
pip install opencv-python==3.4.5.20
Then you can retry import cv2
to see whether the question is solved.
推荐阅读
- node.js - mongoose 乐观并发 - 需要版本控制错误处理时如何跟踪文档更改
- html - 如何在悬停时突出显示元素内的文本,而不是整个元素及其填充?CSS/HTML
- arduino - Esp8266 编程
- ios - 如何在接近结束时更改 UIProgressView 色调颜色
- javascript - 处理内部 div 和外部 div 上的点击事件处理程序
- python - 如何使用递归比较偶数索引?
- python - 在 Pandas 的大型数据集中手动插值 NA
- javascript - Nasa worldwind - 地球动画结束后运行自定义函数
- node.js - 如何将音乐文件直播到
- python - 如果未更改选择,则 QComboBox 中的错误