pycharm 2020.2.2 doesn't find git in wsl2 imported distro


As per docs:

If Git is not installed on Windows, PyCharm searches for Git in WSL and uses it from there. Also, PyCharm automatically switches to Git from WSL for projects that are opened when you use the \wsl$ path.


The new feature in 2020.2 professional allowing configuring of git executable through \\wsl$\ works OK when using the Microsoft Store installed Ubuntu 18.04.

However - any imported version of the same distribution (wsl --import <distro name> <location> <image>) isn't found by found by PyCharm despite it being clearly browsable under Windows, and operating fine under wsl2.

This makes the new feature somewhat limited as one of the key ideas of wsl2 is that you can export and import many images at once.

I guess the question is - what structural assumptions is PyCharm's git locator making about Linux distros?

To reproduce install Ubuntu-18.04 in WSL2.

Export it out:

wsl --export Ubuntu-18.04  my-image.tar

Import it back in:

mkdir my-distro-dir

wsl --import My-18.04 my-distro-dir my-image.tar

Now start-up My-18.04:

wsl -d My-18.04


Note that despite the above process working and My-18.04 distro containing git - PyCharm 2020.2 will not find it AND refuse to browse to it when given the address \\wsl$\My-18.04\usr\bin\git - despite this address being browsable from Windows.

It makes no difference if I make my custom distro the default distro or if I remove all other distros.  I've tried reinstall both WSL and PyCharm - with no change in behaviour.

Lastly I tried changing the underlying git.xml file:

<option name="myPathToGit" value="\\wsl$\My-18.04\usr\bin\git" />

But after restarting PyCharm, it cannot find the location.

If anyone has a fix or workaround I'd be very grateful  - I've tried nesting the ext4 inside a fake LocalState directory - that didn't work?  This is a bit of a deal-breaker in rolling out PyCharm as our Python IDE, so really keen to find a workable solution.

If you need any more info, just let me know.




Some more digging and I've found a very similar issue reported here:


With a solution suggested in the Ruby Mine 2020.2 docs:

This *almost* works by adding the following to the PyCharm config file - wsl.distributions.xml

    <presentable-name>Ubuntu 18.04 - Custom</presentable-name>

The one remaining question (which makes it different to the reported issue) is what to put in the executable-path - given that exported WSL2 builds have no exe - nor do they need one?

The answer seems to be that PyCharm still expects a distro exe to exist - as provided by the template here:


This should be update to work directly with the wsl.exe binary - passing in the -d switch to specify the distribution, rather than have a different exe per distro.


I tried a very quick and ugly hack - of assuming the first param passed is always "run" so ignoring that completely, and then passing the rest to bash via wsl.exe - this got PyCharm to successfully verify git in the git settings page - but git clone is still failing:


@echo off
rem throw the first parameter away
set params=%1
if [%1]==[] goto afterloop
set params=%params% %1
goto loop
C:\Windows\System32\wsl.exe -d My-18.04 --exec bash -c %params%


So it looks like a viable workaround would be to produce a better version of the above script, or even build your own distro exe - but I think this should be resolved in PyCharm.


For now perhaps the best solution is to continue to use wslgit or similar and not to use PyCharm functionality?


Comment actions Permalink

To confirm a (tedious) workaround - if you build your own launcher executable using:

And place the resulting exe under the %LOCALAPPDATA%\Microsoft\WindowsApps and update wsl.distributions.xml to reference the exe - this works as expected.

However a proper fix would be a change to PyCharm itself, so that it calls wsl directly and not through distro launchers.

Comment actions Permalink

Thanks for posting the details.

As you noted, is about the same. I see you have already posted a link there.

Git detection relies on the WSL distros to be properly recognized, so one PY-32424 Git should work as well.

Comment actions Permalink

Thanks for the reply Dmitriy.

The situations is the same as PY-32424 - but the use-case has significantly changed, making the workaround impractical.

In PY-32424 people are talking about one-off distro releases of Arch etc not on Microsoft Store - it's from 2 years ago.

In this case the workaround is reasonable because distributions are already being prepared for download just like distros available on Microsoft Store.

But with WSL2 a new use-case exists where private users can --export and --import images, have many copies of even the same distro installed on a single PC.  These can exist for fairly short periods of time -- having to build a C++ launcher and do XML config each time you export them to get access from PyCharm is tedious.

Looking at the source code for the C++ it doesn't appear the launcher to be doing anything that you can't from the wsl.exe command line anyway?  And given distributions can be specified on the wsl.exe command line, I don't see the requirement to use the launcher?



Please sign in to leave a comment.