Pointing bash to a python installed on windows

a 夏天 提交于 2020-02-17 16:42:11

问题


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:

  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.


来源:https://stackoverflow.com/questions/38794937/pointing-bash-to-a-python-installed-on-windows

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!