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.
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.
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.
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.
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.
Support for WSL is done through the "WSL - Remote" extension. There is a WSL blog post which covers how to get started.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With