Monday, November 4, 2019

[WSL] Set up Visual Studio Code and Pycharm editors in Windows Subsystem for Linux

Last week, I've walked through the initialization of Linux subsystem in Windows (read my blog here). This week, I can't wait to share my experience about the code editors on Windows 10.

Here is some background. I mainly work with Linux and use Python and Javascript. The first question I have is whether I need to install two Python distributions for Windows and WSL. I felt that it may trigger a problem because (1) the compiling of Python in different operating systems must be different, and (2) the slashes in the two file systems are opposite. I did a quick test by launching the anaconda python.exe from the WSL linux terminal (in my case, Ubuntu). Surprisingly, I am able to open Windows Python.exe in WSL! However, it is not much meaningful because in WSL I am not able to invoke the virtual environment and all the packages installed in Windows. So the short answer to this question is that you should install separate Python distribution in Windows and WSL, in order to manage your packages and avoid conflicts. Ideally, one should use virtual environment for each Python project, no matter in Windows or in WSL.

I use two major editors, Visual Studio Code and Pycharm. I use VSC for most languages, such as Python, Javascript, Markdown, Dockerfile, R, etc. I use Pycharm when I focus myself on one single Python project. These two editors are fantastic from their interface designs to the elaborative documentation and online support.


Surprisingly, both editors support dual-system launching! By that I mean, after you install the software in Windows, you not only can open it from Windows (e.g., start menu), but also are able to launch it from the WSL linux terminal (in my case, Ubuntu). I've never seen this dual-system functionality before in Linux nor OSX, which is unbelievably amazing and smart! This feature is really important because the running/debugging environment is entirely different in Windows and WSL. With that, you can now run Python from VSC internally (with your WSL bashrc file launched).

To install and launch Pycharm in both Windows and WSL systems, please follow this guide: python-development-on-the-windows-subsystem-for-linux-wsl.

To install and launch Visual Studio Code in Windows, please follow this official guide: windows. To further launch VSC in WSL, please follow this official guide: run-in-wsl. At the bottom left of the VSC window, there is a green panel displaying which system you are now invoking VSC.

2 comments: