Pointing bash to a python installed on windows

Moon_Raven picture Moon_Raven · Aug 5, 2016 · Viewed 7.3k times · Source

I am using Windows 10 and have Python installed. The new update brought bash to windows, but when I call python from inside bash, it refers to the Python installation which came with the bash, not to my Python installed on Windows. So, for example, I can't use the modules which I have already installed on Windows and would have to install them separately on the bash installation.

How can I (and can I?) make bash point to my original Windows Python installation? I see that in /usr/bin I have a lot of links with "python" inside their name, but I am unsure which ones to change, and if changing them to Windows directories would even work because of different executable formats.

Answer

Rich Turner picture Rich Turner · Dec 1, 2016

As of Windows 10 Insider build #14951, you can now invoke Windows executables from within Bash.

You can do this by explicitly calling the absolute path to an executable (e.g. c:\Windows\System32\notepad.exe), or by adding the executable's path to the bash path (if it isn't already), and just calling, for example, notepad.exe.

Note: Be sure to append the .exe to the name of the executable - this is how Linux knows that you're invoking something foreign and routes the invocation request to the registered handler - WSL in this case.

So, in your case, if you've installed Python 2.7 on Windows at C:\, you might invoke it using a command like this from within bash:

$ /mnt/c/Python2.7/bin/python.exe

(or similar - check you have specified each folder/filename case correctly, etc.)

HTH.