pythonvisual-studio-codeautocompleteopencvjedi

Autocomplete for cv2 not working properly in vscode


I'm trying to figure out why does the autocomplete for cv2 package is not working properly. Below some information about issue and versions that I'm using and my attempts to solve it:

Autocomplete in VS Code

enter image description here

Versions information

All 3 packages above are installed at C:\...\anaconda3\lib\site-packages

My attempts

PS: I've limited the output because questions have a limitation regarding number of characters, can't bring them all.

>>> print(jedi.Script("import cv2\ncv2.").completions())
<stdin>:1: DeprecationWarning: Deprecated since version 0.16.0. Use Script(...).complete instead.
[<Completion: >, <Completion: absdiff>, <Completion: ACCESS_FAST>, <Completion: ACCESS_MASK>, <Completion: ACCESS_READ>, <Completion: ACCESS_RW>, <Completion: ACCESS_WRITE>, <Completion: accumulate>, <Completion: accumulateProduct>, <Completion: accumulateSquare>, <Completion: accumulateWeighted>, <Completion: ADAPTIVE_THRESH_GAUSSIAN_C>, <Completion: ADAPTIVE_THRESH_MEAN_C>, <Completion: adaptiveThreshold>, <Completion: add>, <Completion: addText>, <Completion: addWeighted>, <Completion: AffineTransformer>, <Completion: AGAST_FEATURE_DETECTOR_AGAST_5_8>, <Completion: AGAST_FEATURE_DETECTOR_AGAST_7_12D>, <Completion: AGAST_FEATURE_DETECTOR_AGAST_7_12S>, <Completion: AGAST_FEATURE_DETECTOR_NONMAX_SUPPRESSION>, <Completion: AGAST_FEATURE_DETECTOR_OAST_9_16>, <Completion: AGAST_FEATURE_DETECTOR_THRESHOLD>, <Completion: AgastFeatureDetector>, <Completion: AgastFeatureDetector_AGAST_5_8>, <Completion: AgastFeatureDetector_AGAST_7_12d>, <Completion: AgastFeatureDetector_AGAST_7_12s>, <Completion: AgastFeatureDetector_create>, <Completion: AgastFeatureDetector_NONMAX_SUPPRESSION>, <Completion: AgastFeatureDetector_OAST_9_16>, ... 

If anyone could give me a hint, I'll be glad, even to point where the issue really is (VS Code, python extension, jedi package).

And one last information: numpy autocomplete works normally.


Solution

  • I ran into this same issue setting up my Jetson Nano 2GB, following the instructions via Paul McWhorter. After uninstalling the python3-opencv package, this breaks cv2 completions.

    I ran a trace and found that jedi could no longer find the library. My solution was to create a link to a location that it was looking for. I assume that there is a MUCH better way to fix this than my approach.

    cd /usr/lib/python3.6/dist-packages/cv2;ln -s python-3.6/cv2.cpython-36m-aarch64-linux-gnu.so ./__init__.cpython-36m-aarch64-linux-gnu.so
    

    The paths & command syntax will most likely need to change to match your installed version of python.