Using WSL as a Remote Interpreter 1
We have to prepare our Windows system for work with
WSL. So, fulfil the preliminary steps:
- 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:
Windows 10 is eligible for WSL, and build number is greater than
- 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 PowerShelland choose Run as administrator on the context menu):
and enter the following command:
Enable-WindowsOptionalFeature -Online -FeatureName Microsoft-Windows-Subsystem-Linux
Restart your computer.
- 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 featurescommand:
You'll see the settings for developers. Click the option Developer mode:
- Next, start
cmd(click the Windows button in the lower-left corner of the screen and start typing
cmd), and run the
bashcommand. Enter your Linux username and password.
- You have to update to the latest version. To do that, in the
cmdconsole, enter the following command:
sudo apt-get update
And then you should upgrade (having patience is important!):
sudo apt-get upgrade
- Now that you've installed Linux on your Windows system, you have to edit the
/etc/ssh/sshd_config: change the fields
You can do it using
vim, for example:
sudo vim /etc/ssh/sshd_config
- Finally, you have to start your ssh server in the daemon mode. To do this, type the following command:
sudo service ssh start
- Optionally, to learn which SSH daemon is running and where it is listening, type the following command:
sudo $(sudo which sshd) -d:
bashcommand to start a new linux session and then enter
It works! So, close the
Uff! All the preliminary steps are done. Pretty complicated, isn't it?
Configuring remote interpreter via WSL
On this page, click next to Project Interpreter field, and choose :
The Add Python Interpreter dialog box opens:
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.
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 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.
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.
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.
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.