[Django]-Visual Studio Code: Intellisense not working

76πŸ‘

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
πŸ‘€Jerin

63πŸ‘

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

15πŸ‘

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

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

7πŸ‘

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 πŸ™‚

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

6πŸ‘

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

πŸ‘€DYSLEVIUM

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.

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πŸ‘

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

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πŸ‘

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

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.

πŸ‘€Macdara.Dev

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.

πŸ‘€Chris A

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.

πŸ‘€alshafi

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

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!

1πŸ‘

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

πŸ‘€smcs

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.

1πŸ‘

Configure the type checking mode:

In your settings.json file, add a new line with the following setting:

"python.analysis.typeCheckingMode": "basic".

The default value for this line is off, meaning the static analysis is disabled. You have two other possible values which are basic and strict. The basic mode enables basic type checking rules, while strict mode enables all type checking rules at the highest error severity

πŸ‘€amirhossein

0πŸ‘

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

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

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

πŸ‘€Kenneth Odoh

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"
        ]

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.

0πŸ‘

To anyone with a missing imports issue. If you have installed Pylance and Python extensions from VS Code, you should hover your mouse over the missing imports. Then, Pylance will show you an option saying Quick Fix, click on that and select the right interpreter from the pop-up. After that, I don’t see any line under any imports, and autocompletion is working fine. Previously, autocompletion was not working for the missing imports.

0πŸ‘

I was also facing the same issue…try uninstalling the Pylance extension and refreshing or re-opening your workspace folder.
That worked for me. Hope that helps !!

-1πŸ‘

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

Buggy way

import package.module 

Working way

from package import module
πŸ‘€Pomodoro

Leave a comment