PyCharm 2018.1 Help

Using WSL as a Remote Interpreter 1

Prerequisites

We have to prepare our Windows system for work with WSL. So, fulfil the preliminary steps:

  1. First, check that your Windows version and build are appropriate. To do this, click the Windows button in the lower-left corner of the screen and start typing System Information. Choose System Information and see:
    wsl system info

    Windows 10 is eligible for WSL, and build number is greater than 14361.

  2. Second, start PowerShell as an administrator (to do this, click the Windows icon in the lower-left corner of the screen and start typing PowerShell. You'll see the search results. Right-click the command Windows PowerShell and choose Run as administrator on the context menu):
    wsl powershell

    and enter the following command:

    Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux

    Restart your computer.

  3. Third, having done this, turn on the developer mode: again click the Windows icon in the lower-left corner of the screen and start typing developer. You'll see the search results. Click the Use developer features command:
    wsl developer mode command

    You'll see the settings for developers. Click the option Developer mode:

    wsl developer mode
  4. Next, start cmd (click the Windows button in the lower-left corner of the screen and start typing cmd), and run the bash command. Enter your Linux username and password.
  5. You have to update to the latest version. To do that, in the cmd console, enter the following command:
    sudo apt-get update

    And then you should upgrade (having patience is important!):

    sudo apt-get upgrade
  6. Now that you've installed Linux on your Windows system, you have to edit the ssh configuration file /etc/ssh/sshd_config: change the fields PasswordAuthentication to yes, and UsePrivilegeSeparation to no.
    wsl sshd config edit

    You can do it using vim, for example:
    sudo vim /etc/ssh/sshd_config

  7. Finally, you have to start your ssh server in the daemon mode. To do this, type the following command:
    sudo service ssh start
  8. Optionally, to learn which SSH daemon is running and where it is listening, type the following command:
    sudo $(sudo which sshd) -d:
    wsl which sshd

    Launch another cmd session, enter bash command to start a new linux session and then enter ssh 127.0.0.1:

    wsl bash another

    It works! So, close the cmd console.

Uff! All the preliminary steps are done. Pretty complicated, isn't it?

Configuring remote interpreter via WSL

Next, open the Settings dialog, and click the Project Interpreter page.

On this page, click gear icon next to Project Interpreter field, and choose Add:

py interpreter add

The Add Python Interpreter dialog box opens:

py wsl interpreter ssh add

In the left-hand pane of the dialog box, click SSH Interpreter, then specify server information (host, port, and username). You can also select an existing server configuration.

Click Next to continue configuring an interpreter.

In the next dialog window, provide the authentication details to connect to the target server.

specifying authentication details

Select Password or Key pair (OpenSSL or PuTTY) and enter your password or passphrase.

Click Next to proceed with the final configuration step.

In the next dialog window, specify a path to the remote interpeter.

You have to configure the path mappings to let PyCharm know where to look for files inside of WSL. To do that, click browseButton next to the Sync folders field and enter the path to the local project folder and the path to the folder on the remote server.

py wsl interpreter ssh password mapping

You can also select two checkboxes to upload local project directories to the remote server and to enable automatic upload of the local changes to the remote server. Click Finish to complete adding an interpreter.

Running and debugging under WSL

Let's run and debug a script.

To run the script, right-click the editor background and choose Run <script name> on the context menu.

The script runs under the remote interpreter based on WSL.

wsl run

Let's do some debugging: you have to set a breakpoint and launch the debugger session.

  • Place a breakpoint. To do this, click the left gutter at a line where you want to place a breakpoint. See the Creating Line Breakpoints section.
  • To start the debugger session, right-click the editor background and choose Debug <script name>' on the context menu.

The script is debugged under the remote interpreter based on WSL.

wsl debug

Summary

Let's summarize what was done in this tutorial:

  • First, we prepared for installing WSL.
  • Second, we installed ssh, which is required for WSL.
  • In PyCharm, we configured the remote interpreter via WSL.
  • We ran and debugged our script.
Last modified: 27 June 2018

See Also