Configuring Remote Interpreter via WSL
This feature is only supported in the Professional edition.
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. Now go make yourself a coffee as this can take some time!
- 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 Add Remote:
The Configure Python Remote Interpreter dialog box opens:
Pay attention to the Python interpreter path field. Click the browse button () and choose the required interpreter from the
/usr/bin/ directory (
(Actually, you don't nave to choose the interpreter path from there - it's quite possible to have the virtual environment in one's home directory, for example...)
You have to configure the path mappings to let PyCharm know where to look for files inside of WSL. To do that, click the browse button next to the Path mappings field to open Edit Project Path Mappings dialog. Click (or press Alt+Insert). Enter the local path (here
C:). Next, enter the remote path. To do that, in our case click the browse button next to the added remote path, and choose the mapping :
or simply type the code
/mnt/c/, because you might not have the directory
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.