python 在 cmd 中有效,但在 bash 中无效

python works in cmd, but not in bash

我有一个 python 脚本,我想在 MinGW bash 环境中(在 bash 脚本中)运行

我已经安装了 python 3.5 并且在 PATH 中。

这基本上就是我尝试在 cmd 中启动 python,然后在 bash.

中发生的情况
C:\Users\mkhoory-test>python
Python 3.5.0 (v3.5.0:374f501f4567, Sep 13 2015, 02:16:59) [MSC v.1900 32 bit (In
tel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()

C:\Users\mkhoory-test>bash
bash-3.1$ python
 - Cannot openbash-3.1$

我很难过。这可能是什么原因?

在您的 .bashrc 文件中,该文件应位于 C:\Users\[Username]\ 下,您可以为 PATH 添加一个条目。如果该文件不存在,您可以添加它。

PATH=/c/PathToPythonInstallation

如果要添加多个目录,请使用 : 分隔每个条目,这与 ; 的 Windows 规范不同。

如果您在 .bashrc 中设置它,您需要关闭并重新打开 bash shell,或者键入 source ~/.bashrc 加载它.

您还可以使用 exportexport PATH=/c/PathToPythonInstallation.

临时设置 shell 会话生命周期的路径