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 unable to find venv/pythonPath with WSL2 #136

Open
didimelli opened this issue Feb 18, 2022 · 14 comments
Open

Pyright unable to find venv/pythonPath with WSL2 #136

didimelli opened this issue Feb 18, 2022 · 14 comments

Comments

@didimelli
Copy link

Hello,
I am using SublimeText 4, installed on windows, to open a WSL2 project.

All my venvs are in the proj root dir, in the folder .venv (this means that python is at .venv/bin/python).

My pyright settings are the following:

{
    "settings": {
        "python.venvPath": "./.venv",
        "python.pythonPath": "./.venv/bin/python",
    }
}

When I open the log panel, what I see is this:

LSP-pyright: Pyright language server 1.1.222 starting
LSP-pyright: Server root directory: C:\Users\davide.melli\AppData\Local\Sublime Text\Package Storage\LSP-pyright\14.17.6\language-server\node_modules\pyright/dist/
LSP-pyright: No configuration file found.
LSP-pyright: No pyproject.toml file found.
LSP-pyright: Setting pythonPath for service "leaf-radio": "\Ubuntu-20.04\home\didi\leaf\leaf-radio\.venv\bin\python"
LSP-pyright: venvPath \Ubuntu-20.04\home\didi\leaf\leaf-radio\.venv is not a valid directory.
LSP-pyright: stubPath \Ubuntu-20.04\home\didi\leaf\leaf-radio\typings is not a valid directory.
LSP-pyright: Unable to get Python version from interpreter
LSP-pyright: Assuming Python platform Windows
LSP-pyright: Searching for source files
LSP-pyright: File or directory "\Ubuntu-20.04\home\didi\leaf\leaf-radio" does not exist.
LSP-pyright: No source files found.

Is there any way to make Pyright aware of the WSL mount and resolve the paths correctly?

@rwols
Copy link
Member

rwols commented Feb 18, 2022

Are you opening ST4 from within the WSL2 environment? If so, can you open the console with View > Show Console and run the following in the console: view.file_name()

@didimelli
Copy link
Author

Yep, to open it i do /mnt/c/Program\ Files/Sublime\ Text/subl.exe .

About the console output, i get nothing:
image

@jfcherng
Copy link
Collaborator

Yep, to open it i do /mnt/c/Program\ Files/Sublime\ Text/subl.exe .

About the console output, i get nothing: image

What if you open a py file?

@didimelli
Copy link
Author

Oh, sorry, so silly of me. Here the output with a .py file:
image

@rwols
Copy link
Member

rwols commented Feb 18, 2022

I guess WSL2 path handling is broken (did that ever work?). I would suggest you open the folder from ST4 started in a regular Windows environment.

@didimelli
Copy link
Author

If i open ST4, then menu->file->Open Folder->search a WSL folder from the explorer I get the same exact behaviour.

@jfcherng
Copy link
Collaborator

I can reproduce this but I didn't work under WSL2.

@jfcherng
Copy link
Collaborator

jfcherng commented Apr 14, 2022

Fwiw, I tried this with VSCode + Pyright/Pylance emits the same error. Something like

LSP-pyright: venvPath \Ubuntu-20.04\home\didi\leaf\leaf-radio\.venv is not a valid directory.
LSP-pyright: stubPath \Ubuntu-20.04\home\didi\leaf\leaf-radio\typings is not a valid directory.

@didimelli
Copy link
Author

VSCode has this extension https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl which allows you to seamlessy use the linux filesystem.

Here some logs from the LSP:

[Info  - 11:56:02 AM] (12839) Pylance language server 2022.4.0 (pyright 67ee16be) starting
[Info  - 11:56:02 AM] (12839) Server root directory: /home/didi/.vscode-server/extensions/ms-python.vscode-pylance-2022.4.0/dist
[Info  - 11:56:02 AM] (12839) No configuration file found.
[Info  - 11:56:02 AM] (12839) pyproject.toml file found at /home/didi/leaf/leaf-radio.
[Info  - 11:56:02 AM] (12839) Setting pythonPath for service "leaf-radio": "/home/didi/leaf/leaf-radio/.venv/bin/python"
[Info  - 11:56:02 AM] (12839) Loading pyproject.toml file at /home/didi/leaf/leaf-radio/pyproject.toml
[Error - 11:56:02 AM] (12839) Pyproject file "/home/didi/leaf/leaf-radio/pyproject.toml" is missing "[tool.pyright]" section.
[Warn  - 11:56:02 AM] (12839) stubPath /home/didi/leaf/leaf-radio/typings is not a valid directory.
[Info  - 11:56:02 AM] (12839) Assuming Python version 3.8
[Info  - 11:56:02 AM] (12839) Assuming Python platform Linux
[Info  - 11:56:02 AM] (12839) Search paths for /home/didi/leaf/leaf-radio
[Info  - 11:56:02 AM] (12839)   /home/didi/.vscode-server/extensions/ms-python.vscode-pylance-2022.4.0/dist/typeshed-fallback/stdlib
[Info  - 11:56:02 AM] (12839)   /home/didi/leaf/leaf-radio
[Info  - 11:56:02 AM] (12839)   /home/didi/leaf/leaf-radio/typings
[Info  - 11:56:02 AM] (12839)   /home/didi/.vscode-server/extensions/ms-python.vscode-pylance-2022.4.0/dist/typeshed-fallback/stubs/...
[Info  - 11:56:02 AM] (12839)   /home/didi/.vscode-server/extensions/ms-python.vscode-pylance-2022.4.0/dist/bundled/stubs
[Info  - 11:56:02 AM] (12839)   /home/didi/.pyenv/versions/3.8.12/lib/python3.8
[Info  - 11:56:02 AM] (12839)   /home/didi/.pyenv/versions/3.8.12/lib/python3.8/lib-dynload
[Info  - 11:56:02 AM] (12839)   /home/didi/leaf/leaf-radio/.venv/lib/python3.8/site-packages
[Info  - 11:56:02 AM] (12839) Adding fs watcher for library directories:
 /home/didi/.pyenv/versions/3.8.12/lib/python3.8
/home/didi/.pyenv/versions/3.8.12/lib/python3.8/lib-dynload
/home/didi/leaf/leaf-radio/.venv/lib/python3.8/site-packages
[Info  - 11:56:02 AM] (12839) Adding fs watcher for directories:
 /home/didi/leaf/leaf-radio

@jfcherng
Copy link
Collaborator

jfcherng commented Apr 14, 2022

VSCode has this extension marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl which allows you to seamlessy use the linux filesystem.

Not open sourced so we have no idea what it does. Without its aid, VSCode just emits the same error message. I.e., something like

LSP-pyright: venvPath \Ubuntu-20.04\home\didi\leaf\leaf-radio\.venv is not a valid directory.
LSP-pyright: stubPath \Ubuntu-20.04\home\didi\leaf\leaf-radio\typings is not a valid directory.

@didimelli
Copy link
Author

as the docs says:

With VS Code and the Remote - WSL extension combined, VS Code’s UI runs on Windows, and all your commands, extensions, and even the terminal, run on Linux. You get the full VS Code experience, including autocomplete and debugging, powered by the tools and compilers installed on Linux.

@jfcherng
Copy link
Collaborator

I think this should happen in every non-VSCode editors. Maybe there is already a solution in them (neovim, etc...).

@didimelli
Copy link
Author

I am quite sure that the Intellij suite has a similar solution, but unfortunately not open source!

@deathaxe
Copy link
Contributor

\\wsl.localhost\<distro>\... is the path windows applications can use to access WSL2 filesystem. It doesn't matter whether they are executed directly from Windows or from within WSL2.

A path translation algorithm just needs to be aware of all possible combinations of running [ Linux | Windows ] App in [ WSL | Windows ] accessing [ Linux | Windows ] paths.

Some inspiration may be taken from https://github.com/SublimeText/WslBuild/blob/ebf26d251d5aeab99f515fca3c5947314c5841aa/plugin.py#L260-L276. Those lines have also found their way into GitGutter, to enable it to use Git for Windows to diff files located within WSL2 filesystem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants