Vscode-python: Extension switches back to Jedi when reloading after setting Pylance as the default language server

Created on 8 Oct 2020  路  10Comments  路  Source: microsoft/vscode-python

Environment data

  • VS Code version: 1.49.3
  • Extension version (available under the Extensions sidebar): v2020.9.114305
  • OS and version: Windows 10 2004
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
  • Relevant/affected Python packages and their versions:
  • Relevant/affected Python-related VS Code extensions and their versions: Pylance (v2020.10.0)
  • Value of the python.languageServer setting: Jedi

Expected behaviour

Changed the language server to Pylance, and it should stay Pylance.

Actual behaviour

Pylance extension suggests me to change to it's language server.
Pylance suggestion to change language server

Click 'Yes, and reload'

settings.json
settings.json

Python extension changes the language server back to Jedi and asks me to reload
Python extension asking to reload the window

I go check settings.json and to my surprise:
settings.json

Steps to reproduce:

  1. Install Python extension and Pylance extension.

  2. Create Python 'project' with these settings in .vscode

settings.json:

{
    "python.pythonPath": "C:\\Users\\tiago\\AppData\\Local\\Programs\\Python\\Python38\\python.exe"
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Current File",
            "type": "python",
            "request": "launch",
            "program": "${file}",
            "console": "externalTerminal"
        }
    ]
}
  1. Python code:
print('hello')
info needed type-bug

All 10 comments

Can you check your "Python Language Server" log window to see if Pylance is starting? And could you provide the logs from the Python output window?

image

Do you happen to have any workspace settings that could be overriding it?

As far as I know, the fallback to Jedi should happen transparently if needed without changing the setting, but I could be wrong.

Can you check your "Python Language Server" log window to see if Pylance is starting? And could you provide the logs from the Python output window?

image

Do you happen to have any workspace settings that could be overriding it?

As far as I know, the fallback to Jedi should happen transparently if needed without changing the setting, but I could be wrong.

@jakebailey

The output for "Python Language Server"

[Info  - 20:54:26] Pylance language server 2020.10.0 (pyright d1f950ac) starting
[Info  - 20:54:26] Server root directory: c:\Users\summo\.vscode\extensions\ms-python.vscode-pylance-2020.10.0\dist
[Error - 20:54:26] stubPath c:\Users\summo\Desktop\testbench.py\typings is not a valid directory.
[Error - 20:54:27] stubPath c:\Users\summo\Desktop\testbench.py\typings is not a valid directory.

(this was after reloading from changing to Pylance, meanwhile the message to reload the window to switch between language servers appeared)

Output for "Python"

User belongs to experiment group 'ShowPlayIcon - start'
User belongs to experiment group 'DebugAdapterFactory - experiment'
User belongs to experiment group 'PtvsdWheels37 - experiment'
User belongs to experiment group 'UseTerminalToGetActivatedEnvVars - control'
User belongs to experiment group 'LocalZMQKernel - experiment'
User belongs to experiment group 'CollectLSRequestTiming - control'
User belongs to experiment group 'CollectNodeLSRequestTiming - experiment'
User belongs to experiment group 'EnableIPyWidgets - experiment'
User belongs to experiment group 'RunByLine - experiment'
User belongs to experiment group 'CustomEditorSupport - control'
User belongs to experiment group 'pythonaacf'
> conda --version
> pyenv root
> python3.7 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3.6 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python3 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python2 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> python c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.7 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3.6 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -3 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> py -2 c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import sys;print(sys.executable)"
> conda info --json
Starting Pylance language server.
Python interpreter path: ~\AppData\Local\Programs\Python\Python38\python.exe
Error 2020-10-08 20:54:25: Failed to get interpreter information for 'C:\Users\summo\AppData\Local\Microsoft\WindowsApps\python3.exe' Error: Command failed: "C:\\Users\summo\AppData\Local\Microsoft\WindowsApps\python3.exe" "c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py" "c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\interpreterInfo.py"
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
    at ChildProcess.exithandler (child_process.js:304:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:430:11)
    at Socket.emit (events.js:223:5)
    at Pipe.<anonymous> (net.js:664:12) {
  killed: false,
  code: 9009,
  signal: null,
  cmd: '"C:\\\\Users\\summo\\AppData\\Local\\Microsoft\\WindowsApps\\python3.exe" "c:\\Users\\summo\\.vscode\\extensions\\ms-python.python-2020.10.289937622-dev\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\summo\\.vscode\\extensions\\ms-python.python-2020.10.289937622-dev\\pythonFiles\\interpreterInfo.py"'
}
Error 2020-10-08 20:54:25: Failed to get interpreter information for 'C:\Users\summo\AppData\Local\Microsoft\WindowsApps\python.exe' Error: Command failed: "C:\\Users\summo\AppData\Local\Microsoft\WindowsApps\python.exe" "c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py" "c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\interpreterInfo.py"
Python was not found but can be installed from the Microsoft Store: https://go.microsoft.com/fwlink?linkID=2082640
    at ChildProcess.exithandler (child_process.js:304:12)
    at ChildProcess.emit (events.js:223:5)
    at maybeClose (internal/child_process.js:1021:16)
    at Socket.<anonymous> (internal/child_process.js:430:11)
    at Socket.emit (events.js:223:5)
    at Pipe.<anonymous> (net.js:664:12) {
  killed: false,
  code: 9009,
  signal: null,
  cmd: '"C:\\\\Users\\summo\\AppData\\Local\\Microsoft\\WindowsApps\\python.exe" "c:\\Users\\summo\\.vscode\\extensions\\ms-python.python-2020.10.289937622-dev\\pythonFiles\\pyvsc-run-isolated.py" "c:\\Users\\summo\\.vscode\\extensions\\ms-python.python-2020.10.289937622-dev\\pythonFiles\\interpreterInfo.py"'
}
Error 2020-10-08 20:54:25: Detection of Python Interpreter for Command python3 and args  failed as file  does not exist
Error 2020-10-08 20:54:26: Detection of Python Interpreter for Command py and args -2 failed as file Python 2 not found!

 -3.8-64 does not exist
Error 2020-10-08 20:54:26: Detection of Python Interpreter for Command py and args -3.6 failed as file Python 3.6 not found!

 -3.8-64 does not exist
Error 2020-10-08 20:54:26: Detection of Python Interpreter for Command py and args -3.7 failed as file Python 3.7 not found!

 -3.8-64 does not exist
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import jupyter"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py -c "import notebook"
> conda --version
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s c:\Users\summo\Desktop\testbench.py\test.py
cwd: c:\Users\summo\Desktop\testbench.py
> ~\AppData\Local\Programs\Python\Python38\python.exe c:\Users\summo\.vscode\extensions\ms-python.python-2020.10.289937622-dev\pythonFiles\pyvsc-run-isolated.py flake8 --format=%(row)d,%(col)d,%(code).1s,%(code)s:%(text)s c:\Users\summo\Desktop\testbench.py\test.py
cwd: c:\Users\summo\Desktop\testbench.py
##########Linting Output - flake8##########
21,1,W,W293:blank line contains whitespace
22,5,F,F841:local variable 'wait' is assigned to but never used
27,1,W,W391:blank line at end of file

The workspace settings are the ones you can see above.

settings.json:

{
    "python.pythonPath": "C:\\Users\\tiago\\AppData\\Local\\Programs\\Python\\Python38\\python.exe"
}

Is python.languageServer set to a specific value in your User settings for your VS Code installation (not the workspace settings)?

Is python.languageServer set to a specific value in your User settings?

The issue is all about that, isn't it?
I may change it to Pylance, but as soon as I open a Python file, the extension changes it back to Jedi.

The key thing is knowing where the setting is set, because it can be set in many places. The global user config, in a workspace settings.json, in a code-workspace file. We've had bugs in the past where we were only considering one and not the other, setting it in the wrong place, etc, so eliminating any additional locations helps greatly.

But, judging by this behavior, this could be the settings migrator. It's likely that the languageServer setting has been around long enough that we could consider dropping it and not worrying about many many month old configs.

The setting is set in the User settings. The ones you set in one of these options! And yes, in the User tab if using the UI option.
Command palette search for Settings

The settings.json file location for final clarification:
C:\Users\summo\AppData\Roaming\Code\User\settings.json

Can you check that file to see if there's a setting python.jediEnabled, even commented out?

That was it! python.jediEnabled was set to true and causing the extension to set it as the Language Server.

Thank you!

Thanks for confirming. For reference, it's this way because before the languageServer setting was the only setting, jediEnabled needed to be set explicitly to false to get any LS to work. Now jedi is "just another LS setting", but for compatibility we had to roll people forward; explicitly setting jedi to true meant that we were forcing it to be the LS.

There's a TODO to remove this, as at this point I'm not expecting there to be many machines configured this way intentionally anymore.

Was this page helpful?
0 / 5 - 0 ratings