AttributeError: module ‘cv2’ has no attribute ‘imread’ but no file name

  Kiến thức lập trình

(I’m using VScode on Mac)

I can import cv2, but it went wrong when running image = cv2.imread(path, cv2.IMREAD_COLOR).
I get this error:

 image = cv2.imread(path, cv2.IMREAD_COLOR)
AttributeError: module 'cv2' has no attribute 'imread'

I run print(dir(cv2)) and get this:

['__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']

There is a similar question on stackoverflow, it says that I might have a file. However, I have checked that and cv2 still work on my Mac yesterday. Also, I have tried reinstalling opencv-python and opencv-contrib-python for several time, but it still don’t work.

When using conda, I install opencv by running conda install -c conda-forge opencv , but I result in ModuleNotFoundError: No module named 'cv2'.

How can I fix this? Thx!!

New contributor

user25535416 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.