0

When I use the opencv with the python, I always get an error. I set the environment like this:

  1. install the python "python-2.7.5.msi"
  2. install the numpy "numpy-MKL-1.7.1.win32-py2.7.exe"
  3. install the opencv "opencv-python-2.4.6.win32-py2.7.exe"

Everything is OK. I test it using the following code:

import cv2
img = cv2.imread('lena.bmp')
cv2.show('Image', img)
cv2.waitKey(0)

But I got an error as follow:

 File "E:\Python\cv2.py", line 1, in <module>
         import cv2
 File "E:\Python\cv2.py", line 2, in <module>
      img = cv2.imread('lena.bmp') 
 AttributeError: 'module' object has no attribute 'imread'

Why? But when I print "import cv2" in the IDLE, I didn't get any error.

2
  • 1
    Did you name the file you were testing it in "cv2.py"? Commented Oct 7, 2013 at 7:42
  • Yes, I named the file cv2.py. I have renamed it and now it's successful, thank you very much@JeremyBentham Commented Oct 7, 2013 at 7:48

1 Answer 1

2

well, I guess you imported your file, ie the file you are writing. cause the file is using the name "cv2.py" as it suggested. you`d better change the filename.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.