DEV Community

Davide Mauri
Davide Mauri

Posted on

WSL2, Windows, Python and Node: resolving some conflicts

Lately I've been working with Python and Node both on Windows on WSL (WSL2 specifically) and I noticed a certain number of inconveniences with WSL when having Python and Node installed on both systems. For example, some node packages were found when running node on WSL, even if I never installed them there. When that happened, the performances were horrible.

The reason is that, by default, Windows injects Windows path environment variable into WSL path.

For Node I was able to solve almost any problem using nvm, but with Python I had more challenges, so I decided to solve the problem right from at source.

First, tell WSL not to automatically add windows path to WSL. This can be done via wsl.conf file, as documented in the Advanced settings configuration in WSL.

Edit (or create if not already existing) the file:

sudo nano /etc/wsl.conf
Enter fullscreen mode Exit fullscreen mode

and then add the interop setting:

[interop]
appendWindowsPath = false
Enter fullscreen mode Exit fullscreen mode

Then close all WSL windows, open a Powershell or Command prompt and make sure WSL subsystem has shut down:

wsl --shutdown 
Enter fullscreen mode Exit fullscreen mode

Now you can re-open WSL session and check that the path doesn't automatically contain Windows paths:

echo $PATH | tr ":" "\n"
Enter fullscreen mode Exit fullscreen mode

The second - and last - step is to manually add path to the Windows tools you want to use with WSL too, for example VS Code. I'm using ZSH so I needed to update the .zshrc file and add VS Code path:

export PATH="$PATH:/mnt/c/Users/damauri/AppData/Local/Programs/Microsoft VS Code/bin"
Enter fullscreen mode Exit fullscreen mode

Done. No more conflicts or slow performances, but I can still use Windows tool on WSL. Perfect!

Oldest comments (0)