Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Autocomplete not working for OpenCV built from source #1926

Closed
sanatmharolkar opened this issue Mar 3, 2020 · 6 comments
Closed

Autocomplete not working for OpenCV built from source #1926

sanatmharolkar opened this issue Mar 3, 2020 · 6 comments

Comments

@sanatmharolkar
Copy link

Environment data

  • VS Code version: 1.42.1
  • Extension version (available under the Extensions sidebar): 2020.2.64397
  • OS and version: Ubuntu 18.04.
  • Python version (& distribution if applicable, e.g. Anaconda): 2.7.17 64-bit
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions: OpenCV 3.4.9
  • Relevant/affected Python-related VS Code extensions and their versions: XXX
  • Jedi or Language Server? (i.e. what is "python.jediEnabled" set to; more info How to update the language server to the latest stable version vscode-python#3977): Tried both
  • Value of the python.languageServer setting: XXX

OpenCV 3.4.9 built from source with CUDA support and non-free packages, installed in /usr/local.

/usr/local/lib , /usr/local/lib/python2.7/dist-packages and /usr/local/lib/python2.7/site-packages are added to "python.autoComplete.extraPaths"

Expected behaviour

Autocomplete suggestions for module cv2 are expected.

Autocomplete works in PyCharm IDE, so that proves nothing wrong with my installation of OpenCV.

Actual behaviour

The only suggestions I get :
Screenshot from 2020-03-03 12-58-17

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Mar 3, 2020
@t31060
Copy link

t31060 commented Mar 6, 2020

i have the same issue but i use python 3.7.5

@sanatmharolkar
Copy link
Author

Created a symbolic link in /usr/local/python2.7/site-packages to the cv2.so file that is in /usr/local/python2.7/dist-packages/cv2.
Added /usr/local/python2.7/site-packages to the python.autocomplete.extraPaths setting and it seems to have solved the problem.

@t31060
Copy link

t31060 commented Mar 12, 2020

Created a symbolic link in /usr/local/python2.7/site-packages to the cv2.so file that is in /usr/local/python2.7/dist-packages/cv2.
Added /usr/local/python2.7/site-packages to the python.autocomplete.extraPaths setting and it seems to have solved the problem.

How can i do that on Windows?

@zePanzerfaust
Copy link

@t31060 execute the following command with administrator priviledges (change the name of the *.pyd file in both locations)
mklink "<python_dir>\Lib\site-packages\cv2.cp39-win_amd64.pyd" "<python_dir>\Lib\site-packages\cv2\python-3.9\cv2.cp39-win_amd64.pyd"
This should then output
symbolic link created for <python_dir>\Lib\site-packages\cv2.cp39-win_amd64.pyd <<===>> <python_dir>\Lib\site-packages\cv2\python-3.9\cv2.cp39-win_amd64.pyd

@t31060
Copy link

t31060 commented Apr 8, 2021

@t31060 execute the following command with administrator priviledges (change the name of the *.pyd file in both locations)
mklink "<python_dir>\Lib\site-packages\cv2.cp39-win_amd64.pyd" "<python_dir>\Lib\site-packages\cv2\python-3.9\cv2.cp39-win_amd64.pyd"
This should then output
symbolic link created for <python_dir>\Lib\site-packages\cv2.cp39-win_amd64.pyd <<===>> <python_dir>\Lib\site-packages\cv2\python-3.9\cv2.cp39-win_amd64.pyd

still no autocompletion after doing that, is there something else i must do while building opencv from source to get the auto completion?

@zePanzerfaust
Copy link

zePanzerfaust commented Apr 8, 2021

@t31060 execute the following command with administrator priviledges (change the name of the *.pyd file in both locations)
mklink "<python_dir>\Lib\site-packages\cv2.cp39-win_amd64.pyd" "<python_dir>\Lib\site-packages\cv2\python-3.9\cv2.cp39-win_amd64.pyd"
This should then output
symbolic link created for <python_dir>\Lib\site-packages\cv2.cp39-win_amd64.pyd <<===>> <python_dir>\Lib\site-packages\cv2\python-3.9\cv2.cp39-win_amd64.pyd

still no autocompletion after doing that, is there something else i must do while building opencv from source to get the auto completion?

The response was meant for

How can i do that on Windows?

creating a symbolic link. Not to fix the auto-completion issue with VS Code. Sorry to give false hope :D.

It seems that the Python language servers from Microsoft not necessarily support that.
The current one used is Pylance as far as I know. You can check which one you are using in the settings under Python: Language Server

Pylance does not support auto-completion from *.pyd files according to microsoft/pylance-release#70.
It would only work if you create a stub file *.pyi. I don't know how to do that with OpenCV code or from a *.pyd file.
python-language-server similar discussion at #1125, not sure what the conclusion should be, it should work?

But when I switched Python: Language Server to Jedi it showed autocompletion for cv2. Even though VS Code automatically set the setting back to Microsoft...

So maybe this works for you.

My current environment is

Version: 1.55.0 (user setup)
Commit: c185983a683d14c396952dd432459097bc7f757f
Date: 2021-03-30T16:01:55.261Z
Electron: 11.3.0
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Windows_NT x64 10.0.19042
Python Extension: ms-python.python v2021.3.680753044

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants