将 bash 指向安装在 windows 上的 python
Pointing bash to a python installed on windows
我正在使用 Windows 10 并安装了 Python。新的更新将 bash 带到了 windows,但是当我从 bash 内部调用 python 时,它指的是 bash 附带的 Python 安装=],而不是我的 Python 安装在 Windows 上。因此,例如,我不能使用我已经安装在 Windows 上的模块,而必须在 bash 安装上单独安装它们。
我如何(我可以吗?)使 bash 指向我原来的 Windows Python 安装?我看到在 /usr/bin 中我有很多链接 "python" 在他们的名字里,但我不确定要更改哪些,如果将它们更改为 Windows 目录甚至可以工作,因为不同的可执行格式。
我没有安装 Windows 10,但我使用 Babun,我遇到了同样的问题。正如我所读,别名在 Windows 10 shell 中运行良好,因此只需在指向 Python 安装目录的 .bashrc 中添加别名即可:
alias python /mnt/c/Python27/python
您至少有四个选项:
- 指定要使用的 python 可执行文件的完整绝对路径。
- 在您的 .bashrc 文件中定义一个别名
- 修改 .bashrc 文件中的 PATH 变量以包含您希望使用的 python 版本的位置。
- 在您的 PATH 中已有的目录中创建一个符号链接。
从 Windows 10 Insider build #14951 开始,您现在可以从 Bash.
中调用 Windows 可执行文件
您可以通过显式调用可执行文件的绝对路径(例如 c:\Windows\System32\notepad.exe
)或将可执行文件的路径添加到 bash 路径(如果尚未添加)来执行此操作,并且只是调用,例如,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.
因此,在您的情况下,如果您在 Windows 上的 C:\ 上安装了 Python 2.7,您可以从 bash 中使用如下命令调用它:
$ /mnt/c/Python2.7/bin/python.exe
(或类似的 - 检查您是否正确指定了每个 folder/filename 案例等)
HTH.
我正在使用 Windows 10 并安装了 Python。新的更新将 bash 带到了 windows,但是当我从 bash 内部调用 python 时,它指的是 bash 附带的 Python 安装=],而不是我的 Python 安装在 Windows 上。因此,例如,我不能使用我已经安装在 Windows 上的模块,而必须在 bash 安装上单独安装它们。
我如何(我可以吗?)使 bash 指向我原来的 Windows Python 安装?我看到在 /usr/bin 中我有很多链接 "python" 在他们的名字里,但我不确定要更改哪些,如果将它们更改为 Windows 目录甚至可以工作,因为不同的可执行格式。
我没有安装 Windows 10,但我使用 Babun,我遇到了同样的问题。正如我所读,别名在 Windows 10 shell 中运行良好,因此只需在指向 Python 安装目录的 .bashrc 中添加别名即可:
alias python /mnt/c/Python27/python
您至少有四个选项:
- 指定要使用的 python 可执行文件的完整绝对路径。
- 在您的 .bashrc 文件中定义一个别名
- 修改 .bashrc 文件中的 PATH 变量以包含您希望使用的 python 版本的位置。
- 在您的 PATH 中已有的目录中创建一个符号链接。
从 Windows 10 Insider build #14951 开始,您现在可以从 Bash.
中调用 Windows 可执行文件您可以通过显式调用可执行文件的绝对路径(例如 c:\Windows\System32\notepad.exe
)或将可执行文件的路径添加到 bash 路径(如果尚未添加)来执行此操作,并且只是调用,例如,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.
因此,在您的情况下,如果您在 Windows 上的 C:\ 上安装了 Python 2.7,您可以从 bash 中使用如下命令调用它:
$ /mnt/c/Python2.7/bin/python.exe
(或类似的 - 检查您是否正确指定了每个 folder/filename 案例等)
HTH.