Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why doesn't Visual Studio Code recognize my WSL bash python?

I am running Visual Studio Code on Windows 10 with WSL bash as its terminal:

"terminal.integrated.shell.windows": "C:/Windows/sysnative/bash.exe"

In WSL bash I have both python (v2.7) and python3 (v3.6) installed.

I have installed the Python extension for VS Code. Unfortunately VS Code fails to recognize either version of Python in WSL bash.

For example when I try to discover tests, I get the following error in the Python Test Log output window:

Test Discovery failed:

Error: spawn python ENOENT

How can I configure VS Code to work with Python form WSL bash?

Note: I'm pretty sure I need to configure a path to Python in the "python.pythonPath" key in VS Code's user settings file. I am unsure of which path to put as the value though.

like image 791
urig Avatar asked Jan 30 '18 15:01

urig


People also ask

Why is VS Code not detecting python?

Install Python and the Python extension# Once you have a version of Python installed, activate it using the Python: Select Interpreter command. If VS Code doesn't automatically locate the interpreter you're looking for, refer to Environments - Manually specify an interpreter.

How do I run a python WSL code in Visual Studio?

The file should be visible in the VS Code now. Add the print statement as shown in below snippet. Next, right click on file and select Run Python File in Terminal option to run the python file. This would run the python file and show the output in the terminal.

Why is WSL not recognized?

The term 'wsl' is not recognized as the name of a cmdlet, function, script file, or operable program. Ensure that the Windows Subsystem for Linux Optional Component is installed. Additionally, if you are using an ARM64 device and running this command from PowerShell, you will receive this error.

How does VS Code connect to WSL?

From VS CodeStart VS Code. Press F1, select WSL: New WSL Window for the default distro or WSL: New WSL Window using Distro for a specific distro. Use the File menu to open your folder.


1 Answers

Support for WSL is done through the "WSL - Remote" extension. There is a WSL blog post which covers how to get started.

like image 105
Brett Cannon Avatar answered Sep 22 '22 14:09

Brett Cannon