pyright language server crashes when run from inside venv created by uv
i'm not sure what's causing this, but for some reason all of my language servers are crashing with strange errors when running from a venv created by uv (tested with both ruff and basedpyright language servers).
to reproduce
-
install uv using pyprojectx:
Invoke-WebRequest https://github.com/pyprojectx/pyprojectx/releases/latest/download/wrappers.zip -OutFile wrappers.zip; Expand-Archive -Force -Path wrappers.zip -DestinationPath .; Remove-Item -Path wrappers.zip ./pw --add uv -
./pw uv add ruff -
./pw uv add basedpyright -
install the ruff and basedpyright vscode extensions
-
set the python interpreter (F1 > "Python: Select Interpreter" > ".venv")
-
restart vscode (probably not necessary but just in case)
-
click the Output tab in the terminal and select "Ruff" from the dropdown
2024-08-22 11:34:42.274 [info] Using interpreter: c:\Users\user\project\.venv\Scripts\python.exe 2024-08-22 11:34:42.274 [error] Error while trying to find the Ruff binary: Error: No pyvenv.cfg file 2024-08-22 11:34:43.149 [info] Falling back to bundled executable: c:\Users\user\.vscode\extensions\charliermarsh.ruff-2024.42.0-win32-x64\bundled\libs\bin\ruff.exemy venv does include the
pyvenv.cfgfile so i don't know why that error is occurring: -
check the basedpyright output:
[Error - 12:04:17 PM] Server process exited with code 3221225477. [Error - 12:04:17 PM] Server initialization failed. Message: Pending response rejected since connection got disposed Code: -32097 [Info - 12:04:17 PM] Connection to server got closed. Server will restart.
environment info
windows 11, python 3.12, vscode 1.92.2, uv 0.3.1, ruff 0.6.1
Thanks, that's really strange. @dhruvmanila, would you have any ideas here?
Interesting, not sure. I'd need to look
Installing pyprojectx requires a pyproject.toml file. What does that look like? Does it need to be specific to pyprojectx?
sorry i shouldve updated the issue. pyprojectx is not required to reproduce the issue, i included those steps just in case but a colleague was able to reproduce the issue by installing uv normally.
i should also mention that i can't reproduce those ruff errors anymore, only the basedpyright errors.
sorry i shouldve updated the issue. pyprojectx is not required to reproduce the issue, i included those steps just in case but a colleague was able to reproduce the issue by installing uv normally.
So, should the steps be the following?
- Install uv
-
uv init -
uv add ruff -
uv add basedpyright - Install the "basedpyright" VS Code extension, disable Pylance extension
- Open VS Code, select the virtual environment
It's working fine on MacOS at least, let me (or ask someone) try it on a Windows machine.
hmm this is very odd, i can't seem to reproduce the issue anymore. i'll just close this issue for now and i will investigate further and reopen it once i have more info. sorry to waste your time
nevermind it does still happen with those steps, i just forgot to restart vscode so it was using the version of basedpyright bundled with the extension instead of the one in the venv.
also reproduced with the pyright pypi package
-
uv add pyright -
uv run pyright --versionto trigger the wrapper thing to install the npm package (might not be necessary) - install generic lsp client (3rd party extension is required because pyright/pylance doesn't have a way to run the lsp from your python environment)
- add the following to your
.vscode/settings.json:{ "glspc.languageId": "python", "glspc.serverCommand": ".venv\\Scripts\\pyright-langserver.exe", "glspc.serverCommandArguments": [ "--stdio" ] } - restart vscode
- open a python file
- go to the Output tab and select "glspc" from the dropdown:
starting glspc... Server process exited with code 3221225477 and signal null Server process exited with code 3221225477 and signal null Server process exited with code 3221225477 and signal null Server process exited with code 3221225477 and signal null Server process exited with code 3221225477 and signal null
so i tried to investigate this further on my end and came to the conclusion that it's something to do with the basedpyright-langserver.exe wrapper binary in .venv/Scripts. after installing basdepyright with uv, replacing the one created by uv with the one created by pip makes it work again.
i also found that passing shell: true when launching the language server from the vscode extension fixes it. https://github.com/DetachHead/basedpyright/pull/613
looks like this was the same issue as #6464 which has been fixed