microsoft / microsoft/pyright

Pyright is using Incorrect Interpreter Path

Open
#11,689 2 comments 0 reactions 1 assignee Claimed by @StellaHuang95 View on GitHub
bug
Dominant language
Python
Stars
15.6k
Forks
1.8k
Avg merge
12h 13m
Merged PRs (30d)
52

Description

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:

1. create the following `settings.json`
```json
{
"python.languageServer": "None",
}
```
2. install the `python` and `pyright` plugins
3. create a virtual environment with a name beginning with `python` (e.g. `python_env`)
4. activate the virtual environment
3. open vscodium in an empty directory
4. create an open a `.py` file

The output of the python plugin:
```
2024-01-09 21:30:31.040 [info] Telemetry level is off
2024-01-09 21:30:31.040 [info] Experiments are disabled, only manually opted experiments are active.
2024-01-09 21:30:31.065 [info] Default formatter is set to null for workspace /tmp/workspace
2024-01-09 21:30:31.073 [info] VS Code was launched from an activated environment: 'python_env', selecting it as the interpreter for workspace.
2024-01-09 21:30:31.076 [info] Test server listening.
2024-01-09 21:30:31.079 [info] Python interpreter path: ~/.virtualenvs/python_env/bin/python
2024-01-09 21:30:31.112 [info] Editor support is inactive since language server is set to None.
2024-01-09 21:30:31.159 [info] Send text to terminal: source ~/.virtualenvs/python_env/bin/activate
```
The output of the pyright plugin:
```
[Info - 21:30:31] Pyright language server 1.1.345 starting
[Info - 21:30:31] Server root directory: file:///home/matthew/.vscode-oss/extensions/ms-pyright.pyright-1.1.345/dist
[Info - 21:30:31] Starting service instance "workspace"
Received pythonPath from Python extension: /home/matthew/.virtualenvs/python_env
[Info - 21:30:31] Setting pythonPath for service "workspace": "/home/matthew/.virtualenvs/python_env"
[Info - 21:30:31] Unable to get Python version from interpreter
[Info - 21:30:31] Found 1 source file
```
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 version (& distribution if applicable, e.g. Anaconda): 3.11.6
- Type of virtual environment used (e.g. conda, venv, virtualenv, etc.): Venv
- Value of the `python.languageServer` setting: None

Output for Python in the Output panel (ViewOutput, change the drop-down the upper-right of the Output panel to Python)

```
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: enabled
canvas_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|

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.