Car*_*ris 192 python windows git command-line git-bash
Python不会在git bash(Windows)中运行.当我在命令行中键入python时,它将我带到一个空白行,而不是说它已经像在Powershell中那样输入了python 2.7.10.它没有给我一个错误消息,但python只是不运行.
我已经确定了PATH中的环境变量c:\python27
.我还能检查什么?
发生此问题的会话如下所示:
user@hostname MINGW64 ~
$ type python
python is /c/Python27/python
user@hostname MINGW64 ~
$ python
Run Code Online (Sandbox Code Playgroud)
......坐在那里而不回到提示.
Vit*_*iev 308
只需在windows上的git shell中输入它 - > alias python='winpty python.exe'
,就是这样,你将拥有python可执行文件的别名.请享用
PS对于永久别名添加,请参见下文,
cd ~
touch .bashrc
Run Code Online (Sandbox Code Playgroud)
然后打开.bashrc,从上面添加命令并保存文件.您需要通过控制台创建文件,或者无法使用正确的名称保存文件.您还需要重新启动shell以应用更改.
vav*_*vav 63
我没有在答案列表中看到下一个选项,但我可以使用"-i"键获得交互式提示:
$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55)
Type "help", "copyright", "credits" or "license" for more information.
>>>
Run Code Online (Sandbox Code Playgroud)
Cha*_*ffy 57
这是MSys2中的一个已知错误,它提供了Git Bash使用的终端.您可以通过运行没有ncurses支持的Python构建或使用WinPTY来解决它,如下所示:
要在mintty或Cygwin sshd中运行Windows控制台程序,请将console.exe添加到命令行:
Run Code Online (Sandbox Code Playgroud)$ build/console.exe c:/Python27/python.exe Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 10 + 20 30 >>> exit()
msys的预构建二进制文件可能与Git Bash一起使用.(如果自此答案发布以来已经过了很长时间,请检查是否有更新的版本!).
从Git for Windows 2.7.1开始,也尝试使用winpty c:Python27/python.exe
; WinPTY可以包含在开箱即用中.
hyg*_*ull 41
我是Windows 10用户,我只是接受默认值,在我的系统中安装了GIT.
在阅读了上述答案后,我得到了2个自己的解决方案,这2个解决方案完美适用于GIT bash,方便我在GIT bash 上执行Python语句.
我附上了我的GIT bash终端的3张图片.第1个有问题,后2个有解决方案.
问题 -光标刚打之后等待python
命令
解决方案1
winpty <path-to-python-installation-dir>/python.exe
在GIT bash终端上执行.
注意:不要C:\Users\Admin
在GIT bash中使用类似的路径样式,而是使用/C/Users/Admin
.
就我而言,我winpty /C/Users/SJV/Anaconda2/python.exe
在GIT bash 上执行了命令
或者,如果您不知道您的用户名,请执行winpty /C/Users/$USERNAME/Anaconda2/python.exe
解决方案2
只需输入即可python -i
.
谢谢.
Har*_*rry 11
嗨。这是(对我而言)直接从 Win 10 上的 Git Bash 运行 Python(Python 2.7 和 Python 3.x)的最佳解决方案 => 将别名添加到 Git Bash 用于的别名文件中。
Git Bash 别名文件是aliases.sh。 它位于:
C:\path where you installed Git\etc\profile.d\aliases.sh
例如:在我的情况下,文件在 C:\Software\Develop\Git\etc\profile.d\aliases.sh
在我的情况下,python.exe安装在:
C:\Networking\Network Automation\Python 2.7\python.exe
C:\Networking\Network Automation\Python 3.7\python.exe
Run Code Online (Sandbox Code Playgroud)
所以,你必须创建2别名,一个为Python 2(我命名python2)和其他的Python 3(我命名只是蟒蛇)的Git Bash使用Linux的文件结构,就需要改变“\”为“/” ,如果你有一个像我的示例网络自动化的路径,你把它放在“”
“网络自动化”,例如。
winpty 是调用可执行文件的魔法命令。
所以在aliases.sh的开头添加这些行
alias python2='winpty C/Networking/"Network Automation"/"Python 2.7"/python.exe'
alias python='winpty C/Networking/"Network Automation"/"Python 3.7"/python.exe'
Run Code Online (Sandbox Code Playgroud)
我还修改了ll别名以显示所有文件并在一个人类可读的列表中:
alias ll='ls -lah'
Run Code Online (Sandbox Code Playgroud)
现在,您可以永久地直接从 Git shell 启动这两个 Python,只需编写
$ python
-> 启动 Python 3
$ python2
-> 启动 Python 2
$ ll
-> 输入 ls -lah 以快速显示您的详细文件列表
干杯,哈利
除了@ Charles-Duffy的答案,您可以直接使用winpty而无需安装/下载任何额外的东西.只要运行winpty c:/Python27/python.exe
.可以在Git\usr\bin找到实用程序winpty.exe.我正在使用Git for Windows v2.7.1
来自@ Charles-Duffy的预构建二进制文件是版本0.1.1(根据文件名),而包含的二进制文件是0.2.2
2 个解决方法,而不是解决方案:在我的 Git Bash 中,以下命令挂起并且我没有得到提示:
% python
Run Code Online (Sandbox Code Playgroud)
所以我只是使用:
% winpty python
Run Code Online (Sandbox Code Playgroud)
正如上面有些人所指出的,您还可以使用:
% python -i
Run Code Online (Sandbox Code Playgroud)
2020 年 7 月 14 日:Git 2.27.0 添加了对伪控制台的可选实验支持,允许从命令行运行 Python:
小智 6
类型:'winpty python',它会工作
gitbash 在运行任何以 python 开头的命令时有一些问题。这也适用于任何 python manage.py 命令。总是从 'winpty python manage.py' 开始至少这对我有用。运行 Windows 10。
您可以从以下位置更改 Git Bash 快捷方式的目标:
"C:\Program Files\Git\git-bash.exe" --cd-to-home
Run Code Online (Sandbox Code Playgroud)
到
"C:\Program Files\Git\git-cmd.exe" --no-cd --command=usr/bin/bash.exe -l -i
Run Code Online (Sandbox Code Playgroud)
这是 ConEmu 用来启动 git bash(版本 16)的方式。最近的版本正常启动,这就是我到达那里的方式......
nev*_*new -3
看看这个答案:
Git Bash 中的路径应如下设置:
PATH=$PATH:/c/Python27/
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
105548 次 |
最近记录: |