3

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

  • opencv-python: 4.4.0.46
  • jedi: 0.17.2
  • numpy: 1.19.4

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

  • Visual Studio Code: 1.50.1
  • Python extension: v2020.10.332292344
  • Python version: 3.8.3

My attempts

  • I've checked whether my packages are installed in default location, suggested by this question with no success. They are installed at default location and still not working.

  • The command line print(jedi.Script("import cv2\ncv2.").completions()) brings me the auto-completion correctly when I execute it in PowerShell, as recommended in this issue, but still not working in VS Code. Result are below:

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>, ... 
  • Have tried to update numpy package to the newest one (1.19) and also tried to use an older version (1.10). No success.

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.

Henrique Branco
  • 1,778
  • 1
  • 13
  • 40
  • What is the content you want to see in the autocomplete? And have you tried using other Python language services? For example: Extension: "[Pylance](https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance)". – Jill Cheng Nov 06 '20 at 09:01
  • I want to see the attributes and methods of `cv2` package, and none of them are shown. I'm also using `pylance`, forgot to mention it in question. – Henrique Branco Nov 06 '20 at 17:37

1 Answers1

1

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.

panellaj
  • 26
  • 3
  • How do I adapt your solution to Windows? And I'm also using Anaconda distribution – Henrique Branco Nov 07 '20 at 01:48
  • 2
    I'm using Linux so I can only provide a suggestion. Locate the dist-packages/cv2 under anaconda, then instead of using a "link" just copy the file. There should be a "python3.6" directory, copy the library in that directory to the dist-packages/cv2 directory as `__init__.cpython-36m-aarch64-linux-gnu.so` – panellaj Nov 07 '20 at 15:34