PyCharm 2020.1 Help

Configure an interpreter using WSL

You can use Windows Subsystem for Linux (WSL) to work with a Python interpreter available in your Linux distribution.

Fulfill the preliminary steps

  1. Ensure that you have downloaded and installed Python on your computer.

  2. Click the Windows button in the lower-left corner of the screen and start typing System Information. To ensure that your system works well with WSL, upgrade your Windows to the latest available version.

  3. Install the Windows Subsystem for Linux and initialize your Linux distribution as described in the WSL Installation Guide.

  4. If your Linux distribution doesn't come with rsync, you need to install it:

    sudo apt install rsync
    sudo pacman -S rsync

Configure remote interpreter via WSL

  1. Press Ctrl+Alt+S to open the project Settings/Preferences.

  2. In the Settings/Preferences dialog Ctrl+Alt+S, select Project <project name> | Project Interpreter. Click the The Configure project interpreter icon and select Add.

  3. In the left-hand pane of the dialog, click WSL.

    Adding a WSL interpreter
  4. Select the Linux distribution and specify the path to the python executable in the selected Linux distribution.

Once done, the new interpreter will be added to your project, and the default mnt mappings will be set.

Newly added WSL interpreter

Note that with WSL you cannot create virtual environments: all packages you install will be added to the corresponding system interpreter. You will be asked to enter your sudo password.

Entering your sudo password

PyCharm allows you to use custom Linux distributions run on WSL. This can be done by editing the wsl.distributions.xml configuration file created by PyCharm automatically after detecting WSL.

Add a custom distribution

  1. Open the %APPDATA%\JetBrains\<product><version>\config\options\wsl.distributions.xml file.

  2. Add the descriptor element and provide settings to access your custom distribution. Note that the id value should be unique. For example:

    <![CDATA[ <!-- ... --> <descriptor> <id>Arch</id> <microsoft-id>Arch</microsoft-id> <executable-path>c:/linux/arch.exe</executable-path> <presentable-name>Arch</presentable-name> </descriptor> <!-- ... -->]]>

    Consult the Windows registry to check the id and executable-path values.

    Custom WSL distribution config details in the Windows registry

  3. Restart PyCharm and add your custom distribution as a remote interpreter as described above.

    Configure Python Interpreter

Configure Terminal

  1. To run Terminal in WSL configuration, open project Settings/Preference (Ctrl+Alt+S) and go to Tools | Terminal.

  2. Type wsl.exe in the Shell path field and click Ok.

    Terminal settings
  3. Switch to the Terminal tool window and type any command to inspect the output.

    Terminla in WSL configurations
Last modified: 23 June 2020