2

I have compiled and installed OpenCV from source, and it works perfect, importing and using it in IDLE IDE or CMD working well. But when using PyCharm to import OpenCV, there are no errors, but it is warning me that the function or OpenCV variables, can not find. It is a screenshot from the PyCharm IDE:

enter image description here

There is a warning that imread() function not found.

In the IDE Settings, I did not find any way to configure the OpenCV, all settings seem OK, one more screenshot:

enter image description here

So this problem caused IDE does not autocomplete or suggest the parameters and so on...

But when running the program, it works well without any problem.

Note: When installing OpenCV with PyCharm IDE add packages, then it is OK. But I need to use the one which is compiled from source and installed locally.

Edit: This the screenshot of IDLE IDE, which you can see the autocomplete works well.

enter image description here

List of packages:

enter image description here

In this list, there is no cv2, which the other packages in the dir are listed here

Bahramdun Adil
  • 5,907
  • 7
  • 35
  • 68
  • Are you running in a virtual environment? And have you chosen the right project interpreter? File --> Settings --> Project --> Project Interpreter. – Christoffer May 29 '19 at 07:16
  • No, I am not choosing the virtual environment, and yes, I have chosen the right project interpreter, and while running the program, there is no problem, it is running well, only PyCharm, not loading/detecting OpenCV to autocomplete and recognize the OpenCV functions. – Bahramdun Adil May 29 '19 at 07:19
  • You can try installing jedi (https://pypi.org/project/jedi/) or have you tried the solutions from here: https://stackoverflow.com/questions/44659906/pycharm-opencv-autocomplete-with-import-cv2-cv2-no-errors-with-import-cv2 ? – Christoffer May 29 '19 at 07:26
  • Yes< I did try these two solutions, but the problem still exists, I don't know what is wrong with IDE. If I install from PyCharm inside, then everything goes well, but the prebuilt version of OpenCV I don't want. So I compiled one by myself. – Bahramdun Adil May 29 '19 at 07:33
  • Okay, I have compiled opencv and running Pycharm on Ubuntu 18.04 with no problems but you are running windows, right? That might be the issue. I can go through my pycharm settings to check if you are missing something. – Christoffer May 29 '19 at 07:59
  • OK, thanks in advance! For more clearity, I have edit the question and added Settings screenshot. – Bahramdun Adil May 29 '19 at 08:08
  • In my Interpreter Paths I also got my dist-packages and when I run `print(cv2.getBuildInformation())` I can see that opencv is located in dist-packages. Can you get the opencv buildinformation and see if it aligns with your Interpreter Paths? – Christoffer May 29 '19 at 08:24
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/194091/discussion-between-bahramdun-adil-and-christoffer). – Bahramdun Adil May 29 '19 at 08:28

1 Answers1

0

I had exactly this problem with OpenCV 4.2.0 compiled from sources, installed in my Conda environment and PyCharm 2020.1.

I solved this way:

  1. Select project interpreter
  2. Click on the settings button next to it and then clicking on the Show paths for selected interpreter
  3. adding the directory containing the .so cv2 library (in my case in the Conda Python library path - e.g. miniconda3/lib/python3.7/site-packages/cv2/python-3.7). In general check the site-packages/cv2/python-X.X directory)
Marco
  • 2,389
  • 2
  • 16
  • 19