如果我在CMD中这样做,它可以正常工作,但如果我在Git Bash中尝试它,它不起作用.我喜欢使用Git Bash作为我唯一的控制台,但如果它不适用于Python 3.4,我就不能这样做.
示例如下图所示.这可以很容易地再现.卸载Python和Git(如果已安装),安装Python 3.4,安装Git 2.5.1并获得该结果.
如何让Python解释器在Git Bash中运行?
Cas*_*all 43
MinTTY终端是Git的新默认终端,它不支持Windows控制台程序.我不知道为什么决定更改默认终端,但我知道有几种方法可以解决这个问题:
Bash别名(放在你的.bashrc中):
alias python=winpty py.exe
Run Code Online (Sandbox Code Playgroud)
注意:从Git for Windows 2.7.1开始,Winpty开箱即用.可以找到winpty安装在Git\usr\bin.
Bash别名(放在你的.bashrc中):
function maybe_py() {
if [ $# -eq 0 ]; then
/c/Windows/py.exe -i
else
/c/Windows/py.exe $@
fi
}
alias python=maybe_py
Run Code Online (Sandbox Code Playgroud)
请注意,使用箭头键浏览命令历史记录可能无法正常工作:
py -i
Run Code Online (Sandbox Code Playgroud)
或者对于脚本:
py script.py
Run Code Online (Sandbox Code Playgroud)
bes*_*sil 11
你需要显式的python交互模式:python -i
您可以在.bashrc中定义别名:alias python ='python -i',但是这样做,您将无法运行脚本文件(即:python script.py).
在这里找到: 使用Cygwin的Windows Python
建立在@Darthfett的答案上。我必须确保有引号,而不要引用.exe文件
所以最后 .bashrc
alias python='winpty python'
alias pip='winpty pip' # Rescue pip as well
那是所有的作品
Tawanda@Tawanda-PC MINGW64 ~
$ alias python='winpty python'
Tawanda@Tawanda-PC MINGW64 ~
$ python
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> exit()
Run Code Online (Sandbox Code Playgroud)
Tawanda@Tawanda-PC MINGW64 ~
$ alias pip='winpty pip'
Tawanda@Tawanda-PC MINGW64 ~
$ pip -v
Usage:
pip <command> [options]
Commands:
install Install packages.
download Download packages.
uninstall Uninstall packages.
freeze Output installed packages in requirements format.
list List installed packages.
show Show information about installed packages.
Run Code Online (Sandbox Code Playgroud)
您可以通过编辑“$HOME/.bashrc”中的文件来配置 git bash 控制台
将此行添加到您的$HOME/.bashrc
export PATH=$PATH;c:/python34
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
13597 次 |
| 最近记录: |