Search code examples
pythonshellwindows-subsystem-for-linuxwindows-terminal

Configuring Windows Terminal for WSL Python development


With the new Windows Terminal, it's possible to set up arbitrary shells in tabbed terminals, and it configures quite a few, including Powershell, Cmd, and WSL (Ubuntu 20.04 in my case though I assume it would have more if I installed them).

However, I'd like to be able to set up a Python "shell", to load up the Ubuntu WSL instance then automatically have it run Python within there for me. At the moment, I'm having to start Ubuntu and then manually run Python from within there. My settings for this are:

{
    "guid": "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
    "hidden": false,
    "name": "Ubuntu-20.04",
    "startingDirectory": "//wsl$/Ubuntu-20.04/home/pax",
    "source": "Windows.Terminal.Wsl"
}

Since I often use Python for very quick'n'dirty REPL things, I'd rather be able to have it start in a tab automatically. Is there a way to configure Windows Terminal to do this? For what it's worth, I'm using the 1.2-preview version.


Solution

  • Use the command wsl to execute the internal program.

    {
        "acrylicOpacity" : 0.75,
        "closeOnExit" : true,
        "colorScheme" : "Campbell",
        "commandline" : "wsl.exe -d Ubuntu -e python3",
        "cursorColor" : "#FFFFFF",
        "cursorShape" : "bar",
        "fontFace" : "Consolas",
        "fontSize" : 10,
        "guid" : "{07b52e3e-de2c-5db4-bd2d-ba144ed6c273}",
        "historySize" : 9001,
        "icon" : "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
        "name" : "Python",
        "padding" : "0, 0, 0, 0",
        "snapOnInput" : true,
        "startingDirectory" : "%USERPROFILE%",
        "useAcrylic" : true
    },
    

    Here is the command reference.

    https://learn.microsoft.com/en-us/windows/wsl/reference