4

I'm using VS Code with the Python and Pylance extensions. I'm having a problem with the Pylance extension not doing syntax highlight for things like modules and my dataframe. I would expect the modules at the top to be colored green and the df variable to be colored blue.

I am using the default Dark+ Color Theme.

Here's a screenshot of my VS Code with Python and Pylance installed an enabled.

Screenshot of VS Code

  • I have tried changing my python.pythonpath setting.
  • I've added a sys.path where my packages are installed.
  • I made sure to enable editor.semanticHighlighting.enabled in the settings.
  • Pylance is in my settings.json as the language server.
  • Also tried the most recent Pylance version.
  • Tried switching to various Dark/Light themes. No change in behavior.

Here is my settings.json

{
"[python]": {
    "editor.semanticHighlighting.enabled": true
},
"editor.semanticHighlighting.enabled": true,
"editor.semanticTokenColorCustomizations": {},
"python.condaPath": "C:\\Anaconda3\\Scripts\\conda-script.py",
"python.defaultInterpreterPath": "C:\\Anaconda3\\python.exe",
"python.pythonPath": "C:\\Anaconda3\\python.exe",
"python.languageServer": "Pylance",
"python.terminal.activateEnvironment": true

}

This was working last month so I'm not quite sure what's going on. I'm on Windows 10, VS Code 1.47.1, with the newest extensions. Any thoughts as to why this is happening?

MyNameHere
  • 85
  • 2
  • 12

1 Answers1

7

Looks like your Language Server does not work.

Could you add "python.languageServer": "Pylance", in the settings.json? Make sure the Pylance has been enabled. If it still does not work try to reinstall the Pylance and Python extension.

Steven-MSFT
  • 7,438
  • 1
  • 5
  • 13
  • That key:value was already in my settings. I removed it, reloaded vs code, added it back, reloaded vs code, and still no change. I've already tried reinstalling vs code and python half a dozen times without success. – MyNameHere Mar 18 '22 at 03:17
  • @MyNameHere Have you tried to switch the color theme, and do you find `import` and `print` always been colored while `pandas` and `pd` always white? – Steven-MSFT Mar 18 '22 at 03:20
  • Have you selected the python interpreter? Could you run the python script success? – Steven-MSFT Mar 18 '22 at 03:24
  • @MyNameHere Have you tried to reinstall the Pylance or install an older version of it? – Steven-MSFT Mar 18 '22 at 03:25
  • I have tried switching it to other Dark/Light themes, still no coloring as expected meaning modules should be green and variables blue. The python script runs without errors. I've tried reinstalling Pylance and also tried one version prior. I haven't gone back further than 1 version. – MyNameHere Mar 18 '22 at 03:27
  • @MyNameHere Sorry for being late, are you clicke the gear icon and choose Install Another Version? And could you try to delete the pylance(ms-python.vscode-pylance-2021.12.1) cache under `C:\Users\{UserName}\.vscode\extensions`? – Steven-MSFT Mar 18 '22 at 05:22
  • Yes I click on the gear in the extension to switch versions. I just realized I was using version 8.2 as my "newest" and also tried 8.1 and 8.0. I'm guessing 8.2 is the newest I can go because i'm on VS Code version 1.47.1. – MyNameHere Mar 18 '22 at 14:34
  • @MyNameHere What's the version of 8.2? This is my extensions version: `Pylance: v2022.3.2;` `Python: v2022.2.1924087327`. – Steven-MSFT Mar 21 '22 at 09:17
  • @MyNameHere Sorry, but can you update your VSCode? – Steven-MSFT Mar 21 '22 at 09:23
  • 1
    After talking with IT support for a while I was able to update my vscode version to 1.64.2 and pylance 3.2. Everything looks to be working as intended. – MyNameHere Mar 21 '22 at 21:02
  • 1
    I'm having the same problem, except that upgrading versions did not solve... any other tips that were not yet covered in this post? I tried everything here... – RafaJM Jun 24 '22 at 15:19