Repository navigation
Description
Disclosure: This report was written by AI, after interactively investigating the issue. Without AI assistance I probably wouldn't have taken the time to debug it or create instructions for reproduction with a clean VS Code user data dir.
Behaviour
When the Python extension is activated through another extension's API call rather than by opening a Python file, it can show
An Invalid Python interpreter is selected, please try changing it to enable features such as IntelliSense, linting, and debugging.
even though the selected interpreter is valid. The same interpreter is resolved successfully a few seconds later in the same window.
In daily use, this happens intermittently when a single Markdown file is opened in a new window (e.g. via code -n -w as core.editor). The Ruff extension activates on onLanguage:markdown and pulls in the Python Environments and Python extensions (see astral-sh/ruff-vscode#1086), and the warning appears depending on how fast interpreter resolution is. Opening a .py file in the same setup does not show the warning.
Expected
No warning for an interpreter that is valid but not resolved yet. The check should wait for the initial resolution of the active interpreter before reporting it as invalid.
Steps to reproduce
The race is made deterministic with an interpreter that takes 10 s to respond:
- Create a wrapper:
mkdir -p /tmp/slowpy/bin printf '#!/bin/sh\nsleep 10\nexec /usr/bin/python3 "$@"\n' > /tmp/slowpy/bin/python chmod +x /tmp/slowpy/bin/python
- Fresh user data dir with only Python, Python Environments, Pylance, Python Debugger and Ruff installed, and these user settings:
(Trust is disabled only because single files outside trusted folders otherwise open in Restricted Mode, where the Python extension does not run.
{ "security.workspace.trust.enabled": false, "python.locator": "native", "python.defaultInterpreterPath": "/tmp/slowpy/bin/python" }python.locatoris set explicitly because telemetry was off in the test profile, which disables the experiment that normally enables it.) printf '# Test\n\ntext\n' > /tmp/test.md, thencode --user-data-dir <dir> --extensions-dir <dir> -n /tmp/test.md.- The warning appears.
- With a
.pyfile instead of.mdin step 3, no warning appears.
Logs
Timestamps trimmed, paths shortened to match the steps above.
Markdown file, warning shown. Activation order (exthost log):
21:32:12.686 ExtensionService#_doActivateExtension charliermarsh.ruff, startup: false, activationEvent: 'onLanguage:markdown'
21:32:13.028 ExtensionService#_doActivateExtension ms-python.vscode-python-envs, startup: false, activationEvent: 'api', root cause: charliermarsh.ruff
21:32:13.448 ExtensionService#_doActivateExtension ms-python.python, startup: false, activationEvent: 'api', root cause: ms-python.vscode-python-envs
21:32:14.404 ExtensionService#_doActivateExtension ms-python.vscode-pylance, startup: false, activationEvent: 'api', root cause: ms-python.python
Python output:
21:32:13.986 [info] Native locator: Refresh started
21:32:14.019 [info] Native locator: Refresh finished in 208 ms
21:32:14.252 [info] Active interpreter [global]: /tmp/slowpy/bin/python
21:32:16.164 [info] Starting Pylance language server.
Python Locator output, 10 s later:
21:32:24.320 [info] Resolved Python Environment /usr/bin/python3
.py file, no warning. Here the Python extension activates before Python Environments:
21:32:43.819 ExtensionService#_doActivateExtension charliermarsh.ruff, startup: false, activationEvent: 'onLanguage:python'
21:32:43.881 ExtensionService#_doActivateExtension ms-python.python, startup: false, activationEvent: 'onLanguage:python', root cause: ms-python.debugpy
21:32:44.132 ExtensionService#_doActivateExtension ms-python.vscode-pylance, startup: false, activationEvent: 'onLanguage:python'
21:32:44.544 ExtensionService#_doActivateExtension ms-python.vscode-python-envs, startup: false, activationEvent: 'onLanguage:python'
Analysis
In the bundled code, InvalidPythonInterpreterService._manualDiagnose (run via python.triggerEnvSelection, which is also executed on onDidChangeInterpreterConfiguration) calls getActiveInterpreter() once and reports InvalidPythonInterpreterDiagnostic if it returns undefined. It does not distinguish "not resolved yet" from "invalid". The activation order matters, presumably because when the Python Environments extension activates first, an interpreter configuration change is signalled while the active interpreter is still being resolved.
Environment
- VS Code 1.148.0 (661626d0e72f97806550790a98fb87116c9db825), Linux x64, Debian 13
- ms-python.python 2026.10.0
- ms-python.vscode-python-envs 1.44.0
- ms-python.vscode-pylance 2026.4.1
- ms-python.debugpy 2026.6.0
- charliermarsh.ruff 2026.98.0
Activity