Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pyright language server crashes when run from inside venv created by uv #6399

Open
DetachHead opened this issue Aug 22, 2024 · 9 comments
Open
Labels
windows Specific to the Windows platform

Comments

@DetachHead
Copy link

DetachHead commented Aug 22, 2024

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

  1. 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
  2. ./pw uv add ruff

  3. ./pw uv add basedpyright==1.17.0 (i added a workaround in a later release, see comment below)

  4. install the ruff and basedpyright vscode extensions

  5. set the python interpreter (F1 > "Python: Select Interpreter" > ".venv")

  6. restart vscode (probably not necessary but just in case)

  7. 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.exe
    

    my venv does include the pyvenv.cfg file so i don't know why that error is occurring:

    image

  8. 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

@charliermarsh
Copy link
Member

Thanks, that's really strange. @dhruvmanila, would you have any ideas here?

@charliermarsh charliermarsh added the windows Specific to the Windows platform label Aug 22, 2024
@dhruvmanila
Copy link
Member

Interesting, not sure. I'd need to look

@dhruvmanila
Copy link
Member

Installing pyprojectx requires a pyproject.toml file. What does that look like? Does it need to be specific to pyprojectx?

@DetachHead
Copy link
Author

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.

@dhruvmanila
Copy link
Member

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?

  1. Install uv
  2. uv init
  3. uv add ruff
  4. uv add basedpyright
  5. Install the "basedpyright" VS Code extension, disable Pylance extension
  6. 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.

@DetachHead
Copy link
Author

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

@DetachHead DetachHead closed this as not planned Won't fix, can't repro, duplicate, stale Aug 22, 2024
@DetachHead
Copy link
Author

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.

@DetachHead DetachHead reopened this Aug 22, 2024
@DetachHead
Copy link
Author

DetachHead commented Aug 22, 2024

also reproduced with the pyright pypi package

  1. uv add pyright
  2. uv run pyright --version to trigger the wrapper thing to install the npm package (might not be necessary)
  3. 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)
  4. add the following to your .vscode/settings.json:
    {
        "glspc.languageId": "python",
        "glspc.serverCommand": ".venv\\Scripts\\pyright-langserver.exe",
        "glspc.serverCommandArguments": [
            "--stdio"
        ]
    }
  5. restart vscode
  6. open a python file
  7. 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
    

@DetachHead
Copy link
Author

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. DetachHead/basedpyright#613

@DetachHead DetachHead changed the title language servers crash when run from inside venv created by uv pyright language server crashes when run from inside venv created by uv Aug 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Specific to the Windows platform
Projects
None yet
Development

No branches or pull requests

3 participants