I'm using Python3 on Ubuntu 20.04 inside WSL2, running print(sys.executable)
outputs /usr/bin/python3
Within VS Code, pressing "Select Interpreter" then "Enter Interpreter Path" I have tried both /usr/bin/python3
and the full windows path \\wsl$\Ubuntu/\usr\bin/python3
(which is reachable inside file explorer).
Both paths returns the error An Invalid Python interpreter is selected, please try changing it to enable features such as IntelliSense, linting, and debugging.
It seems to only accept an .exe file, how can I select the Linux path as the interpreter? Thanks.
It sounds like either:
There are several options for doing WSL development in VSCode, but all do require that you start by installing (if you haven't already) either:
Then, typically, you'll start VSCode by navigating to your project directory in WSL and:
code .
You'll see that VSCode has switched from "Windows" mode to "WSL" mode in the lower left-hand corner of the status-bar, where you should see "WSL: [distroname]".
With that in place, you should be able to select the Linux Python interpreter.
Alternatively, you can start VSCode through Windows, then switch to WSL mode with the stacked "><" icon in that same location on the status-bar. Or just enter the command-palette and "Remote-WSL: New WSL Window".