2

I am using python 3.7.3 and visual studio code 1.33.1. When I import any library like cv2 or numpy and try to use it, the autocompletion takes 4-5 seconds to identify the functions. When I use the default functions like print(),slice(), etc., they autocomplete within 1 second.

I tried using the following config

"python.linting.pylintArgs": ["--extension-pkg-whitelist=cv2"],
"python.autoComplete.extraPaths": [
    "C:\Users\Pratik\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.7_qbz5n2kfra8p0\LocalCache\local-packages\Python37\site-packages\cv2"
]
import cv2
import numpy
cv2.   #here I need to list all functions

I expect to decrease the autocompletion delay from 4-5 seconds to 1s.

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
Pratik Mohite
  • 95
  • 1
  • 8

1 Answers1

4

In addition to python.autoComplete.extraPaths, try setting the jediEnabled setting to false, to enable the Microsoft Python Language Server (which is disabled by default):

"python.jediEnabled": false

Then restart/reload VS Code.

When the window is reloaded, open the Output tab then click on your Python file. You should see a "Starting Microsoft Python language server." message displayed (select Python from the top-right dropdown to see it). There should also be an "Analyzing in background..." message at the bottom status bar.

output tab

Wait for the "Analyzing.." message to disappear (meaning it's finished). If you're enabling this for the first time, it takes a while to download. Also, check the output logs that the language server is searching the correct site-packages paths (paths added to python.autoComplete.extraPaths should appear in the "Configuration Search Paths").

The autocomplete/intellisense should be much faster now.

gif

Related:

Gino Mempin
  • 25,369
  • 29
  • 96
  • 135
  • This still takes about 2 seconds before it shows up. Is that to be expected? – Destaq Jun 11 '20 at 18:40
  • @Mythaar Hmm I don't know, sorry, it appears quite instantaneous to me on my current env (it actually appears faster than the GIF I posted in this answer). You could try tweaking the [Intellisense settings](https://code.visualstudio.com/docs/editor/intellisense#_customizing-intellisense), especially the `quickSuggestionsDelay`. It's also possible that it's caused by some other extension, so try disabling all extensions except for Python, then re-enable one-by-one. Other than that, I think you'll need to post a new question or raise an issue over at VS Code. – Gino Mempin Jun 11 '20 at 23:55
  • I think it may just be something to do with the `cv2` library. I tried installing tensorflow and calling autocompletions, and that only took half a second. – Destaq Jun 13 '20 at 06:04