1

Hey guys I am using PyCharm to code in python.

Python Version: 3.6.1 CV2 Version: 3.2.0

When I import cv2 with "import cv2" the autocomplete in PyCharm is broken. There are no suggestions with cv2. --> When I'm writing cv2.cv2. --> then I get the right suggestions but the code does not work.

Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
Marker
  • 19
  • 3
  • Possible duplicate of [Autocomplete for OpenCV-Python in Windows not working](http://stackoverflow.com/questions/18672087/autocomplete-for-opencv-python-in-windows-not-working) – thewaywewere May 03 '17 at 17:41
  • Possible duplicate of [PyCharm Opencv - autocomplete with import cv2.cv2, no errors with import cv2](https://stackoverflow.com/questions/44659906/pycharm-opencv-autocomplete-with-import-cv2-cv2-no-errors-with-import-cv2) – Georgy Aug 28 '19 at 06:12

4 Answers4

0

Try the following:

import cv2.cv2 as cv2

That solved the problem for me

Community
  • 1
  • 1
Xaaris
  • 51
  • 5
  • This should be a comment, not an answer. – trincot Dec 16 '18 at 20:12
  • This did not work for me. I've answered how I solved here: https://stackoverflow.com/questions/61190224/opencv-built-from-source-pycharm-doesnt-get-autocomplete-information/61281004#61281004 – Marco Apr 21 '20 at 21:38
0

Encountered this before.

  1. find "cv2.cp38-win_amd64.pyd" in "Lib\site-packages\cv2" path. ("site-packages" path can be found by "pip --version")
  2. Copy it to "DLLs" path. ("DLLs" path is located at "Lib\site-packages....\DLLs")

Work for system python and anaconda environments(need to do this in conda envs path)

nuclearczy
  • 26
  • 4
0

Here's a link to an answer post that works for me. (credit to @dxl. Kindly upvote his/her post if it works for you. I did it too)

In short, I just added another interpreter path in my python interpreter settings that points to:

<my full path to venv>/Lib/site-package/cv2

The steps are:

1. Go to: Settings -> Project -> Python interpreter
2. Click on the "gear symbol" and select "Show All...". This will navigate you to a "Python Interpreters" window.
3. While your intended interpreter is highlighted, click on the "path symbol" which will navigate you to an "Interpreter Paths" window.
4. Click "+" symbol to add path in the interpreter paths window.
5. Add a new interpreter path as shown above.
6. In my case, I needed to restart my PyCharm IDE for the autocompletion to finally work.

As opposed to his/her configurations, my configurations are:

- PyCharm Community Edition 2022.1.1 on Windows 10
- Python 3.9.10 running in a Virtual Environment (Virtualenv)
- opencv-contrib-python 4.6.0.66 installed in the virtual environment via pip command
rachwa
  • 1,805
  • 1
  • 14
  • 17
lambo9495
  • 5
  • 4
0

In the lower right corner PyCharm 1

Show All... 2

Show path for the selected interpreter 3

Add -> /lib/python3.10/site-packages/cv2 -> OK -> Apply 4

OptikRUS
  • 89
  • 1
  • 3
  • 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](/help/how-to-answer). – Community Aug 30 '22 at 09:31