Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting Python interpreter from WSL

I am using Windows 10 and want to set the the default VSCode interpreter for Python to be the same one used in my WSL 2 (Ubuntu), so that I'm always using "one Python".

When I click "Select Python interpreter" a prompt appears to find the interpreter path, but I'm not sure what the path would be.

like image 596
user4367814 Avatar asked Jun 22 '20 12:06

user4367814


People also ask

Where is the Python interpreter path in WSL?

Select File | Open from the main menu. Choose a directory in \\wsl$ . Click Search for Python in Ubuntu to find a Python executable and create a WSL-based interpreter.

How do you select an interpreter in Python?

By default, the Python extension looks for and uses the first Python interpreter it finds in the system path. To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).

How does Python choose valid interpreter?

Change the Python interpreter in the project settingsPress Ctrl+Alt+S to open the IDE settings and select Project <project name> | Python Interpreter. Expand the list of the available interpreters and click the Show All link. Select the target interpreter.


2 Answers

I think that, in order to use the WSL python, you need to be running VSCode in a WSL remote window. You need to install the Remote WSL extension first. Then, on the lower left there is a green button that will let you start a WSL window, or it will tell you that you are already in one.

This shows that you are in a WSL window

If you are in a WSL window, you should be able to select your python interpreter pretty easily. It will either automatically detect it, or you can run which python in an Ubuntu terminal to get the path. If you want to navigate to a file on your Windows file system from within this window, look in, e.g., /mnt/c/Users/<USER_NAME>.

like image 111
h1-the-swan Avatar answered Nov 15 '22 10:11

h1-the-swan


Well probably late to the party but you can find Python you are using on your WSL2 with simple command:

which python3

It will show you where is the python placed.

like image 29
LSWarss Avatar answered Nov 15 '22 08:11

LSWarss