4

I am trying to use match/case from python 3.10, but jedi doesn't support the syntax. I've heard pylance is better, but I can't find any way to switch vscode to pylance. I've downloaded the default Python extension, but only the jedi language server is running. How can I make the switch?

EDIT: Adding a picture of trying to search for "pylance" so there's no confusion, it's not there at all. It seems to claim it's part of the python extension, but the language server being used is always jedi.
enter image description here

Python extension packs: enter image description here

Marcus Hagberg
  • 175
  • 1
  • 11

3 Answers3

7

I was using the open source version of vscode which doesn't have all extensions. Switching to the proprietary version (available on the AUR) fixed my issue.

Marcus Hagberg
  • 175
  • 1
  • 11
  • 1
    Is pylance closed source or why does that happen? The aur package does look a bit hacky. Isnt there another way to get pylance on archlinux running? – NicoHood Nov 13 '22 at 14:57
  • 1
    If this doesn't work by itself, try additionally changing the `python.languageServer` setting to "Pylance" as suggested in other answers. – Scriddie Feb 07 '23 at 09:20
6

Change the setting: python.languageServer

rioV8
  • 24,506
  • 3
  • 32
  • 49
  • 1
    I get the message "The Pylance Extension is not installed but the python.languageServer value is set to "Pylance"[...]". When I click "Download Pylance" vscode does nothing at all. If it's relevant, the python extension has the following uncaught exception: "Extension 'ms-python.python' CANNOT use API proposal: testObserver. Its package.json#enabledApiProposals-property declares: but NOT testObserver. The missing proposal MUST be added and you must start in extension development mode or use the following command line switch: --enable-proposed-api ms-python.python" – Marcus Hagberg Mar 18 '22 at 12:50
  • @MarcusHagberg Then download the Pylance extension from the Marketplace and use the Extension top menu item `Install from VSIX` – rioV8 Mar 18 '22 at 18:29
  • 1
    My marketplace has no "Pylance" extension, only the "Python" one which has Pylance in parenthesis. I am using the [code - oss version](https://github.com/microsoft/vscode) on arch linux. – Marcus Hagberg Mar 20 '22 at 11:55
  • what if you uninstall the python extension, and install it again – rioV8 Mar 20 '22 at 14:49
  • Can you use this link to download and install into vscode:https://marketplace.visualstudio.com/items?itemName=ms-python.vscode-pylance – MingJie-MSFT Mar 21 '22 at 02:51
  • @MarcusHagberg Have you tried the link posted by MingJie – rioV8 Mar 21 '22 at 08:37
  • 1
    Yes, the command opened marketplace search for "ms-python.vscode-pylance" and that just shows the same "Python" extension. Re-installing it does nothing. Does anyone know what the error message I posted in first comment means? It comes from that same python extension. – Marcus Hagberg Mar 21 '22 at 09:41
  • 2
    @Marcus Hagberg It seems to be caused because Python and Pylance extensions have a bit of a circular dependency: Python is declared as an extension pack which includes Pylance and Pylance has a dependency declared on the Python extension.For the first comment, I think you can refer to this article:https://github.com/microsoft/vscode-python/issues/16614 – MingJie-MSFT Mar 23 '22 at 01:13
  • @MingJie I'm not sure that's relevant. The only prompt I have seen is that Pylance is not installed, and asking to install it, which does nothing. Nothing about reloading.I've added a picture to the OP for clarification. – Marcus Hagberg Mar 23 '22 at 11:41
  • @Marcus Hagberg Please provide the vscode version number or try updating manually – MingJie-MSFT Mar 24 '22 at 01:01
  • 1
    My vscode version: 1.65.2-1 – Marcus Hagberg Mar 24 '22 at 13:26
  • @Marcus Hagberg That doesn't seem to be the problem with the vscode version. Can you update the problem? I want to check that there is an entry called extension pack in the python extension you installed. Can you upload that part of the screenshot? There should be Python here – MingJie-MSFT Mar 25 '22 at 05:37
  • Updated now. Should there be a Pylance extension pack listed there? I only have Jupyter – Marcus Hagberg Mar 25 '22 at 11:18
  • @MarcusHagberg On my system there is also the mention of Pylance extension in the pack, I'm using vscode-python v2021.12. Also look in the `packake.json` of `microsoft.vscode-python` for `extensionPack` – rioV8 Mar 25 '22 at 17:05
  • 1
    So I found it a bit "suspicious" no one was commenting on the fact that I was using the strictly open source version of vscode, and found [this page](https://github.com/microsoft/vscode/wiki/Differences-between-the-repository-and-Visual-Studio-Code) where they mention that not all extension are available on both versions, so since this was hindering my workflow I switched to the proprietary version, and Pylance is available and works now. Thanks for the help anyway. – Marcus Hagberg Mar 27 '22 at 17:05
0

Go to Settings > Extensions > Python, head down to Language Server and change Default to Pylance. This fix also works in the Open Source version, VS Codium. It should have nothing to do with the version of VScode you're using.