问题
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.
回答1:
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.
回答2:
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
回答3:
You have at least four options:
- Specify the complete absolute path to the python executable you want to use.
- Define an alias in your .bashrc file
- Modify the PATH variable in your .bashrc file to include the location of the python version you wish to use.
- Create a symlink in a directory which is already in your PATH.
来源:https://stackoverflow.com/questions/38794937/pointing-bash-to-a-python-installed-on-windows