AttributeError: 模块“cv2"没有属性“imread"
(我使用的是 mac os 10.8.5)
(i'm on mac os 10.8.5)
我正在使用 Python 3(通过 jupyter notebook)并尝试 import cv2
I'm using Python 3 (through jupyter notebook) and trying to import cv2
我成功地执行了 import cv2
,但是当我输入 im_g = cv2.imread("smallgray.png", 0)
时,我收到此错误:
I did import cv2
succefully, but when I type im_g = cv2.imread("smallgray.png", 0)
I get this error:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-7-5eb2880672d2> in <module>()
----> 1 im_g = cv2.imread("smallgray.png", 0)
AttributeError: module 'cv2' has no attribute 'imread'
我还检查了 dir(cv2)
并且我得到:
I also checked dir(cv2)
and I get:
['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__'
我想很多功能都丢失了...是不是因为opencv安装错误?实际上,我为获得 opencv 付出了很多努力,我想我通过终端以太多次"和不同的方式安装了它.(brew
, pip
)
I guess a lot of functions are missing...
Is it due to a wrong opencv installation ?
Actually I struggled a lot to get opencv and I guess I installed it 'too many times' and different ways via Terminal. (brew
, pip
)
我应该卸载 opencv 并重新开始吗?我该如何正确执行此操作?
Should I uninstall opencv and start over ? How can I do this properly ?
提前谢谢
可能是您以错误的方式安装了它.就我而言,我错误地安装了 OpenCV,所以我完全卸载了它,然后重新安装了它,这导致它可以工作.
It might be the case that you installed it in the wrong way. In my case as well, I installed OpenCV wrongly so I uninstalled it completely then reinstalled it which caused it to work.
请注意卸载和安装的顺序:
Please notice the sequence of uninstalling and installing:
卸载:
pip uninstall opencv-python
pip uninstall opencv-contrib-python
安装:
pip install opencv-contrib-python
pip install opencv-python