Pointing bash to a python installed on windows

后端 未结 3 564
长情又很酷
长情又很酷 2021-02-04 11:05

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

相关标签:
3条回答
  • 2021-02-04 11:33

    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.

    0 讨论(0)
  • 2021-02-04 11:42

    I do not have Windows 10 installed, but I use Babun and I had the same problem. As I read aliases work well in Windows 10 shell so simply add alias in your .bashrc pointing to your Python installation directory:

    alias python /mnt/c/Python27/python
    
    0 讨论(0)
  • 2021-02-04 11:42

    You have at least four options:

    1. Specify the complete absolute path to the python executable you want to use.
    2. Define an alias in your .bashrc file
    3. Modify the PATH variable in your .bashrc file to include the location of the python version you wish to use.
    4. Create a symlink in a directory which is already in your PATH.
    0 讨论(0)
提交回复
热议问题