VSCode autocomplete not working for OpenCV installed from source

*爱你&永不变心* 提交于 2020-12-06 07:27:25

问题


I've only found one other question asking exactly this with no answer, so I'm asking here.

I am running Ubuntu 18.04, VSCode latest version.

I have installed OpenCV 3.4.9 from source to /usr/local

When I import cv2 and then try to type "cv2.", VSCode is unable to autocomplete. The only suggestions it makes are "bootstrap" and "os". I have no problem with autocomplete with any other module like numpy or rospy, or even when OpenCV is installed from pip. It seems the issue is only when OpenCV is installed from source.

I have tried both the language server as well as Jedi. I have also tried various linters.

Any help is appreciated.


回答1:


I have encountered the same problem. Hope this helps

Its because the package is not installed in the usual location but in a custom location. This problem could be resolved by some configuration changes. Configure the settings.json to include the custom location for autocompletion to work. Add path to python.autoComplete.extraPaths

STEP 1:Identify the location of the custom library/module.

STEP 2: Make the necessary changes in the User Settings or Workspace Settings file.

Here’s a sample entry in the User Settings (Mention the exact location of the module)

    "C:/Program Files (x86)/---/---",
    "C:/Program Files (x86)/---/---/lib" ]



回答2:


In case of Ubuntu 20.04 and manual installation of OpenCV4, the python library path to be added to extraPaths is "/usr/local/lib/python3.8/dist-packages/cv2/python-3.8". Assuming -D CMAKE_INSTALL_PREFIX=/usr/local was used during cmake

Ex: "settings.json" (VScode)

{
"python.analysis.memory.keepLibraryAst": true,
"python.defaultInterpreterPath": "/usr/bin/python3",
"python.autoComplete.extraPaths": [
 "/usr/local/lib/python3.8/dist-packages/cv2/python-3.8"
]}


来源:https://stackoverflow.com/questions/60428259/vscode-autocomplete-not-working-for-opencv-installed-from-source

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!