20

I have opencv-python installed and the .pyd file is added in the site-packages and the DLLs. The code works with images. When I want to read, show, write an image it works.

But I get a warning that the functions' references cannot be found in __init__.py.

Due to this, I can not use the auto-complete feature. I am using OpenCV 3.4.0 and Python 3.6.4 in PyCharm. I downloaded OpenCV via pip in the command prompt.

2
  • The last time I used opencv, it was not compatible with python 3.x, but instead 2.x (2.6 I believe). Unless they have made it compatible with 3.6, you may run into errors down the road (if not now) Commented Feb 13, 2018 at 17:47
  • I think it is compatible now, I have used the customize installation and it is working with images. the problem is with the autocomplete and the warnings Commented Feb 13, 2018 at 18:08

7 Answers 7

27

The problem is caused by CV2 and how __init__.py does the imports. Just ignore the warnings the program will work all the same, or you can do an import with an alias like:

import cv2.cv2 as cv2

If you have a warning on it press Alt+Enter to install and fix it. Now you will have the code completion and no other warnings (about that) on the project.

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

1 Comment

import cv2.cv2 as cv2 gives ImportError: Bindings generation error. Submodule name should always start with a parent module name. Parent name: cv2.cv2. Submodule name: cv2
10

Switching to an older version of opencv solved this problem for me.

Apparently pycharm sometime breaks depending on the version of opencv. For me, the newest version was, 4.6.X unstalling and installing 4.5.X did the trick.

1 Comment

Sad but that's how I got it working. github.com/opencv/opencv/issues/20997. PyCharm should really do something about it.
6

I use python 3.10 and my newest version for opencv is 4.6.0.66 ,by changing opencv version to 4.5.5.62 and with an alias: import cv2.cv2 as cv2 my problem has solved.

Comments

5

Import cv2 as follows:

from cv2 import cv2

5 Comments

How is this different from the upvoted answer?
It's exactly the same but I think it's a more elegant way.
It's a cleaner way
it doesn't work
This does not work with opencv>4.5.5.64
1

I installed version 4.5.5.64 and imported with an alias. import cv2.cv2 as cvv2

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
1

I was using Python 3.10.2288.0 and OpenCV 1.6.0.66. I resolved the issue by rolling back the OpenCV version to 4.5.5.62.

Comments

0

This worked for me-

pip install --force-reinstall --no-cache -U opencv-python==4.5.5.62

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.