[DEBUG Diary] PyCharm cannot automatically complete from cv2

Problem Description

In the process of using PyCharm, sometimes after installing opencv-python, cv2 in the code can run normally, but the function of cv2 cannot be automatically completed in Code, nor can you right-click to view the source code, etc., and there will be a warning background color Block, extremely unfriendly to obsessive-compulsive disorder. Although it does not affect normal use, it is still very annoying not being able to complete it, especially for a rookie like me.


Cause Analysis:

There are many solutions in other blogs, such as

  • Change the __init__ file
  • Move the cv2.**.pyd file to site-packages
  • use import cv2.cv2 as cvalternativeimport cv2 as cv

The core of these methods is to change the path of the import library, change the import path to cv2.cv2, or raise the reference file. These methods can also solve these problems in some cases.
Of course, I am writing this blog because the above methods did not solve my problem.


solution:

My solution:

  1. Open from PyCharm: File -> Settings -> Projects -> Python interpreter;
  2. Click the gear on the right or the drop-down menu -> Show all -;
  3. Select your environment, click the directory-shaped button on the far right of the toolbar Show paths for the selected interpreter -> add the path of cv2, for example:
    D:\anaconda3\envs\base\Lib\site-packages\cv2
  4. After everything is confirmed, wait for the reading at the bottom of PyCharm to end, the loading is complete, and then you can happily complete the code.

Guess you like

Origin blog.csdn.net/lucifer479/article/details/125604048