Open mbway opened 9 months ago
Hi @mbway, it seems to me that https://github.com/microsoft/pyright might be using an older API to getting interpreter path instead of the updated API: https://github.com/microsoft/vscode-python/wiki/Python-Environment-APIs#extension-api-usage. I'm transferring this issue to Pylance to further investigate.
I was able to repro this on Linux and Windows. It won't repro until you launch VS Code from the project directory with the python_env
activated. After that, you can deactivate the venv and it seems to keep reproing, at least within the same terminal session. Can't explain that. I guess something is getting cached somewhere.
Pyright is using Python's settings.getExecutionDetails
API which I think confirms Kartik's suggestion that we're using an outdated API. This doesn't repro in Pylance which uses environments.getActiveEnvironmentPath + environments.resolveEnvironment
.
I was able to repro this in the debugger by setting the following in the launch.json
config. Replace the venv path with the path to your venv. It doesn't need to be under .virtualenvs
. But on Linux you need to use /home/foo
instead of ~
.
"env":{
"VSCODE_CLI": "1",
"VIRTUAL_ENV": "/home/erikd/.virtualenvs/python_env"
}
Type: Bug
Behaviour
Expected vs. Actual
The python plugin sends the incorrect interpreter path to langauge server plugins such as
pyright
if the name of the virtual environment name begins with "python
" (e.g.python_env
) (as far as I can tell from trying many different names).For some reason this only seems to affect the name of the virtualenv itself. If the virtualenv has a path such as
/tmp/python_envs/venv/
then the plugin detects the interpreter path correctly.Steps to reproduce:
settings.json
python
andpyright
pluginspython
(e.g.python_env
).py
fileThe output of the python plugin:
The output of the pyright plugin:
pyright is receiving the root directory of the virtualenv instead of the interpreter path.
A simple workaround is to rename the virtual environment but this is still a bug as the result is unexpected.
Diagnostic data
python.languageServer
setting: NoneOutput for
Python
in theOutput
panel (View
→Output
, change the drop-down the upper-right of theOutput
panel toPython
)``` XXX ```
User Settings
``` languageServer: "None" ```
Extension version: 2023.22.1 VSCodium version: VSCodium 1.85.1 (08e6c15293922dd53a864bb041be381322fee401, 2023-12-14T20:36:42.296Z) OS version: Linux x64 6.1.71-1-lts Modes:
System Info
|Item|Value| |---|---| |CPUs|Intel(R) Core(TM) i7-10870H CPU @ 2.20GHz (16 x 3599)| |GPU Status|2d_canvas: enabledcanvas_oop_rasterization: disabled_off
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
video_decode: enabled
video_encode: disabled_software
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: disabled_off| |Load (avg)|2, 1, 2| |Memory (System)|31.05GB (21.93GB free)| |Process Argv|--ms-enable-electron-run-as-node .| |Screen Reader|no| |VM|0%| |DESKTOP_SESSION|plasma| |XDG_CURRENT_DESKTOP|KDE| |XDG_SESSION_DESKTOP|KDE| |XDG_SESSION_TYPE|x11|