106

My Visual Studio Code's Intellisense is not working properly. Every time I try to use it with Ctrl + Shift, it only displays a loading message. I'm using Python (with Django) and have installed ms-python.python. I also have Djaneiro. It is still not working. enter image description here

What seems to be the problem here?

Sayse
  • 42,633
  • 14
  • 77
  • 146
Donovan Keating
  • 1,715
  • 3
  • 17
  • 27
  • Related?: https://github.com/Microsoft/vscode-python/issues/423 – sshashank124 May 17 '18 at 11:04
  • It looks like you are using python 3.7, please could you confirm this? That version is not yet supported by this extension. – vijesh May 17 '18 at 11:18
  • I am using Python 3.6. – Donovan Keating May 17 '18 at 11:53
  • 1
    Well for me works fine most of the time. But as my file gets larger(at about 500+ lines), it gets really slow, sometimes it might take more than a minute to show suggestions. So I try to keep my views and models small but it's not always possible :( – Vaibhav Vishal Oct 10 '18 at 10:44
  • Hi Donovan, did you ever find a solution to your problem? Do you mind sharing it? – Charlie Parker Jun 24 '20 at 20:04
  • Can you be more precise in your question? Are your issues with your own packages or someone elses like pytorch tensorflow numpy etc? – Charlie Parker Jun 24 '20 at 21:35
  • @CharlieParker do you have this: https://visualstudio.microsoft.com/services/intellicode/ installed? What kind of problem are you facing? Does this: https://stackoverflow.com/questions/53939751/pylint-unresolved-import-error-in-visual-studio-code/53940610#53940610 this help? – ruddra Jun 26 '20 at 06:21

31 Answers31

73

This can be caused by many reasons, some of them are as follows.

  1. Python executable path in vscode is incorrect

    • Solution: Configure the path to the python executable in settings.json. Remember to restart vscode after.
  2. The module is located in a non-standard location

    • Solution: Configure settings.json to include this location for autocompletion to work. An example (for Linux) used to add a custom module for the workspace:

      {
        "python.pythonPath": "/usr/bin/python",
        "python.autoComplete.extraPaths": [
          "${workspaceFolder}/customModule"
        ]
      }
      
  3. vscode was not launched from the active virtual environment

    • Solution: The path to the modules is set when a virtual environment is activated. Launch vscode from a terminal with the correct virtual environment activated
Maximilian Burszley
  • 18,243
  • 4
  • 34
  • 63
Jerin
  • 1,124
  • 9
  • 11
  • 2
    I've discovered that `extraPaths` can recognize multiple modules in one root path like `"${workspaceFolder}/libraries"` – Kyle Delaney May 15 '20 at 18:38
  • 1
    `extraPaths` is exactly what solved the problem for me – Dmitry Kankalovich May 24 '20 at 04:22
  • 4
    your answer is currently not specific enough to be actionable. For example, how do I do your fist suggestion that says: "Python executable path in VS code is incorrect"? – Charlie Parker Jun 24 '20 at 20:05
  • 2
    The `"python.autoComplete.extraPaths"` did it for me! – Joshua Schlichting Aug 12 '20 at 17:02
  • 1
    In my case ( using a venv on a outside dir ) what did the trick for me was: 1. Getting the python path ( which python ) 2. Openning vscode settings.json, and setting the python.pythonPath to this path – Dr4kk0nnys Nov 24 '20 at 15:25
  • The solution using the `python.autoComplete.extraPaths` solved it for me while using a `.venv` virtual environment. – Pablo Alexis Domínguez Grau Jan 25 '21 at 02:42
  • 1
    #1 solved it for me. I'm using pyenv, so I had to hit CTRL+SHIFT+P > Python: Select Interpreter > `Python 3.8.2 64-bit ('3.8.2': pyenv)` and restart VSCode. If you're on WSL like me, you'll need to execute `wsl --shutdown` from the command line. Works like a charm. – Meir Gabay Feb 19 '21 at 10:13
  • My problem was solved by option 2. IntelliSense was working for me, but not for methods of inherited classes. Googling that specific issue turns up many results that lead in the wrong direction. I hope someone with the same problem with Inherited classes not being available in IntelliSense can find your answer. – Amir Almusawi Dec 15 '22 at 18:21
50

Installing Pylance addon caused Vscode Intellisense to stop.
On disabling Pylance and enabling the Default Microsoft Python extension along with Visual Studio IntelliCode(Microsoft) and reverting to the Jedi server(prompted by Vscode) ,restarted intellisense detection.

srt111
  • 1,079
  • 11
  • 20
  • 2
    It was the opposite for me. I had to use `pylance` to get it to work. I was working with the `Remote - SSH` package too at that time. Not sure if it had to do anything with it. – powersource97 Jun 29 '21 at 19:25
  • 5
    It worked for me! Thanks! – Hoa Nguyen Oct 15 '21 at 17:32
  • 2
    I had the exact opposite experience to @powersource97. While running on Remote - SSH, I had to disable pylance to get it to work. ‍♂️ – PCoelho Feb 05 '22 at 18:43
  • 3
    Thanks so much. I just uninstalled the Pylance plugin from VSCode. – nmdaz May 17 '22 at 18:57
  • 1
    Thanks for this tip! After much frustration with VS Code intellisense, disabling the Pylance extension (which is automatically installed/bundled with the MS Python extension) and then restart of VS Code solved the issue for me too. – stephinity Jan 15 '23 at 12:51
14

If you've tried everything but still if it doesn't work, in my case installing the extension Visual Studio IntelliCode with the Python extension worked.

c-shubh
  • 159
  • 3
  • 7
10

First of all if you've installed virtualenv on your project run vscode from there. Then in your vscode settings, i mean settings.json, you can follow my configuration or trace in which one you have a problem. Most of time this problem stem from putting incorrect path in pythonPath setting

    {
  "python.pythonPath": "${workspaceFolder}/env/bin/python3",
  "editor.formatOnSave": true,
  "python.linting.pep8Enabled": true,
  "python.linting.pylintPath": "pylint",
  "python.linting.pylintArgs": ["--load-plugins", "pylint_django"],
  "python.linting.pylintEnabled": true,
  "python.linting.pep8Args": ["--ignore=E501"],
  "files.exclude": {
    "**/*.pyc": true
  }
}

Update:

If you want to have a well-configuration of Vscode That i personally use for developing my Django and React web-applications you can glance this.

Ehsan Ahmadi
  • 1,382
  • 15
  • 16
  • I just fiddled with all the lines which contained "python" in them in the settings.json and then an error asked me to reload my vscode and then the problem is gone! Thanks :) – aderchox Jan 01 '20 at 23:11
  • I don't understand, why do you need to set the manually if I already have a python with a path to all my packages? – Charlie Parker Jun 24 '20 at 21:15
  • Because maybe you are in a virtual environment so the path of python executable is different than that you actually want to use. – Ehsan Ahmadi Jun 27 '20 at 05:08
6

i change change the :jedi true 2 false, or flase 2 true, when reload the VSCode, that's ok.

my setting:

{
    "editor.fontSize": 16,
    "explorer.confirmDragAndDrop": false,
    "extensions.autoUpdate": false,
    "workbench.colorTheme": "Default Dark+",
    "editor.fontFamily": "Consolas, Dengxian",
    "workbench.sideBar.location": "left",
    "workbench.startupEditor": "newUntitledFile",
    "workbench.iconTheme": "material-icon-theme",
    "python.pythonPath": "d:\\Source\\Django\\Scripts\\python.exe",
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "git.ignoreLimitWarning": true,
    "python.jediEnabled": true,
    "python.autoComplete.extraPaths": [
        "d:\\Source\\Django\\",
    ],
    "python.autoComplete.addBrackets": true
}
rogers.wang
  • 416
  • 5
  • 11
  • With VSCode 1.43.2 / Ubuntu 18.04 in a VirtualBox, I fixed a similar issue with this approach. I disabled Jedi with jediEnabled set at false. Microsoft's autocompletion seems to be more efficient than Jedi in my context. – Joël Esponde Apr 08 '20 at 08:28
  • In OSX, changing jedi value actually triggered a re-download of microsoft python extension and started working again. Yay! – pmourelle May 19 '20 at 05:01
  • I don't understand, why do you need to set the manually if I already have a python with a path to all my packages? – Charlie Parker Jun 24 '20 at 21:15
6

In my case , what worked was reinstalling python extension on vscode which auto-install pylance.

then I just hit "ctrl + , " on my keyboard to take me to vscode setting typed: pylance .

clicked on the edit setting.json and change the "python.languageServer" to default

  },
"terminal.integrated.sendKeybindingsToShell": true,
"python.defaultInterpreterPath": "C:source\\env\\Scripts\\python.exe",
"python.disableInstallationCheck": true,
"terminal.integrated.defaultProfile.windows": "Command Prompt",
**"python.languageServer": "Default"**,
"python.analysis.completeFunctionParens": true,
"[jsonc]": {
    "editor.defaultFormatter": "esbenp.prettier-vscode"
},
"python.autoComplete.addBrackets": true,
"diffEditor.ignoreTrimWhitespace": false

and I hope this works for you also else you can try reinstall intellicode and python extension then restart your vscode.

I hope you find this useful :)

Han Kami 王
  • 69
  • 1
  • 2
5

For me Intellisense stops working randomly when working with Python files.

I just save my files, close the file tab then I re-open and its working again.

Sometimes that doesn't work so I just restart VS code and then Intellisense is back online.

GIVE-ME-CHICKEN
  • 1,239
  • 3
  • 15
  • 29
5

Just a warning - the original question was asked several years back. Much has changed in that time, including the old MPLS language server being removed, Pylance shipping (but Jedi being the default), and then since mid 2021, Pylance being the default. If you're having issues check the dates on responses before following the advice given; it may be obsolete. The OP's issue is almost certainly one with MPLS which is long gone. If you are having issues with Pylance, consider opening an issue at https://github.com/microsoft/pylance-release.

Graham Wheeler
  • 2,734
  • 1
  • 19
  • 23
4

I had the same problem, but I googled a bit and found this extension: Pylance, which solved the problem.

Allen M
  • 1,423
  • 9
  • 15
DYSLEVIUM
  • 41
  • 2
3

"If you find IntelliSense has stopped working, the language service may not be running. Try restarting VS Code and this should solve the issue." From https://code.visualstudio.com/docs/editor/intellisense and helped to me

3

For me, what fixed it was reinstalling the default Python extension and setting the python language server in the seetings to Default.

Steps

  1. Open the commands window by simultaneously pressing CTRL/CMD + Shift + P. Now search for install extensions.
  2. Select Python and install it (uninstall first if already installed).
  • Python is the default Python extension in VSCode and it installs Pylance by default.
  1. Open the commands window again and search this time for Settings. Select Prefernces: Open settings (JSON).
  2. In the JSON file search (CTRL/CMD + F) for python.languageServer and set the value to Default or Pylance as the default is currently Pylance (mine was somehow set to None!).
  3. Once you save the file, a prompt will ask you if you want to reload vscode for the changes to take effect, click Yes!

That's it, intelliSense should be working now using Pylance!

Karim Sonbol
  • 2,581
  • 2
  • 18
  • 16
2

I had this issue for a while now. I tried a lot of solutions from stack but none worked. Uninstalling all the extensions did the trick for me.

V Reddy
  • 38
  • 1
  • 5
2

My settings were all in order, but still not auto-completing in-line. I disabled the Kite extension & a couple of other ones that I didn't really need, & IntelliSense started auto-completing. Not 100% sure, but I reckon it might have been my "Kite" extension settings that were getting in the way.

2

In my case, Pylance was stuck at Loading... since the workspace contained too many files (Large dataset and many log files). Upon inspecting the python language server logs:

Enumeration of workspace source files is taking longer than 10 seconds.

Solution

Add a pyrightconfig.json to your workspace root, and create a list with directories to exclude from the Pylance search (https://github.com/microsoft/pyright/blob/main/docs/configuration.md):

{
  "exclude": [
    "**/data",
    "**/.crash_reports",
    "**/runs",
    "**/wandb",
    "**/notebooks",
    "**/models",
    ".git"
  ]
}

Restart the language server

hinge
  • 21
  • 5
2

Something slightly different has worked for me.

  1. Disabled the Pylance extension
  2. Installed the Pyright extension
  3. Restarted VS Code

Voila! All of the suggestions I could ever want.

csgeek
  • 711
  • 6
  • 15
Chris A
  • 21
  • 2
1

I was also facing this problem and it's really annoying. This is a major bug of VS code that happens with installing some of the npm packages. VS code IntelliSense crashes and stops working after a few moments you start the VScode due to unsuccessful loading of the modules of the new package.

In my case, it was solved by using the VScode insiders version: https://code.visualstudio.com/insiders/

Download and install VScode insiders, install all the extension you use and then check if the problem is fixed.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
alshafi
  • 969
  • 7
  • 8
1

I had tried pretty much everything that was listed by others on this page, and none of it worked for me. I was using the Python version from Anaconda.

In the end, the way that I got Python intellisense to start working in VS Code was to:

  1. open up the Terminal (View menu => Terminal)
  2. type conda init powershell
  3. restart VS Code

After that, Python intellisense started working correctly.

Ron Bertino
  • 141
  • 1
  • 7
1

Problem

VSCode Pylance has trouble with pandas.read_csv() and company (pandas.read_pickle(), ...).

Solution

My solution was to call pandas.DataFrame() on the incoming data. This seems to help VSCode Pylance Here's what I had to do:

import pandas as pd

df = pd.read_pickle(
    "path_to_pickle_file.pkl"
)

# Needed to get Pylance Intellisense working
df = pd.DataFrame(df)

Hope this helps someone else. Took me forever to figure it out.

Matt Dancho
  • 6,840
  • 3
  • 35
  • 26
1

Assuming you're using Pylance as your language server, what worked for me (based on this conversation) was adding

"python.analysis.extraPaths": [
    "./src/lib"
],

(where .src/lib/ contains your modules and an __init__.py file) to your settings.json.

Note: the setting is called python.analysis.extraPaths and not python.autoComplete.extraPaths!

Tomasz Bartkowiak
  • 12,154
  • 4
  • 57
  • 62
1

I just disabled Pylance in the extensions and suggestions worked again instantly.

smcs
  • 1,772
  • 3
  • 18
  • 48
1

Go to Vs code Settings > serach for "languageserver" don't put space!

python LanguageServer > change it to > Pylance

finished now it works wee pylance is i think the default server from python extention that's why it works most of the time.

0

In my case, I fix the Intellisense by changing import code.

Buggy way

import package.module 

Working way

from package import module
Pomodoro
  • 9
  • 1
0

In my case there was a problem with the python language server after a vs code update. The download of the language server was stuck every time. See enter link description here What I had to do was to open settings and type "languge server ". Then there are a few options like css, html etc. ( whatever you might have installed )

Select Python and search for lanuge server. Also if it is mentioned that the default is pylance, I had to switch it to Pylance and restart the ide ( update the window )

After this action my intellysense worked again.

FishingIsLife
  • 1,972
  • 3
  • 28
  • 51
0

What worked for me was to uninstall the Python extension & restart VS Code. IntelliSense sprang to life! This may not make sense as I left the extension uninstalled. Your comments are welcome!

  • Update: Well when I tried to do a debug, I needed to reinstall the Python extension. After installing the extension (including Pylance and Jupyter), IntelliSense continued to work fine. Go figure. – David Tarbill Nov 10 '21 at 18:48
0

go to Extensions (Ctrl+Shift+X). you should have installed following extensions: python extensions

*:Note: some of them may needs to be restarted, in this way it is shown in the right side of extension.

0

This worked for me:

In my case, I was working with a conda virtual environment.

I closed up the vs code editor Then, navigated to the root of my virtual environment and relaunched vs code from there code .

Then, in the .vscode folder under my project directory, I opened the settings file and entered the path to the desired python installation (in my case, C:\User\user\miniconda\python.exe

  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Sep 30 '22 at 09:16
0

I use this settings to have full auto-completion support. It isn't obligatory to set "python.defaultInterpreterPath" because you can set it from the status bar. Although if the venv is located in the same place for every developer you can set it for example to "${workspaceFolder}/.venv/bin/python".

{
  // Index installed third party libraries and user files for language features such as auto-import, add import, workspace symbols and etc.
  "python.analysis.indexing": true,
  // Offer auto-import completions.
  "python.analysis.autoImportCompletions": true,
  // Automatically add common search paths like 'src'.
  "python.analysis.autoSearchPaths": true,
}
0

step 1: go to your environment directory of your anaconda or any python virtual env folder that you are using and navigate to :

/lib/python*.*/site-packages : this is where all your enviornment package are installed

step 2: copy the complete path upto site-package

step 3: open settings.json file in vscode

step 4: add the following key-value pair

python.analysis.extraPaths": [
            "full/path/upto/site-packages",
"any/other/path/you/want/to/consider"
        ]
Prason Ghimire
  • 403
  • 4
  • 4
0

I only disabled the AI extention (tabnine in my case)

since the AI extension didn't work, I got neither AI nor pylance (intellisence) autocomplete.

0

I fixed issue by updating VS code the latest version.

Shirantha Madusanka
  • 1,461
  • 1
  • 11
  • 16
0

Finally I found out elegant and Simple Solution:

Add below setting in settings.json

"python.languageServer": "Pylance"
saumilsdk
  • 721
  • 1
  • 7
  • 17