Home  >  Q&A  >  body text

visual-studio - Python OpenCV: 奇怪的自动补全问题

当我使用pip将OpenCV安装好之后,使用visual-studio编写代码时,出现了一个奇怪的问题。使用import cv2导包后,当我输入cv2.时,自动补全并未提示OpenCV内部的函数,而是出现cv2sysos

当我紧接着前一个cv2之后再输入一个cv2后,自动补全才可以正常地补全OpenCV内部的函数。但是大家应该知道,使用import导包后,使用其内部函数时,只需使用一次包名就可使用其中的函数,所以每次写完代码,我还得将多余的cv2删掉,很是麻烦。

我在网上搜索过多次,并未找到解决方法。我曾今怀疑是visual-studio的PTVS的缘故,可是有同学使用的pycharm也出现了同样的错误。所以我觉得可能是pip的原因,不过我并不知道该如何解决,希望有大神相助。

巴扎黑巴扎黑2741 days ago1160

reply all(2)I'll reply

  • 黄舟

    黄舟2017-04-18 10:35:45

    This problem has been solved so far.
    In the above question, I used pip to install python-opencv online. After installation, pip created a folder CV2 in Lib->site-packages under the python installation path, which means python-opencv was installed in Lib->site-packages->CV2; and then I switched to a third-party offline installation package for installation, in which opencv-python was installed under Lib->site-packages, and No additional folders are created. With the latter, the above problems will not occur. Therefore, I speculate that the above problem is caused by pip installing python-opencv online.
    But I don’t understand why this is happening now.
    I checked many similar questions on the Internet, and many of them encountered problems that could not be completed. I think they may have encountered the same problem as me, but they didn't write another onecv2, so they couldn't complete it.

    reply
    0
  • PHPz

    PHPz2017-04-18 10:35:45

    Who should bear the blame==

    Not sure why, I can only help you reduce the number of times you delete cv2

    from cv2 import cv2

    reply
    0
  • Cancelreply