Python 3 无法从 Git Bash 命令行运行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35471179/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python 3 Wont run from the Git Bash command line
提问by Scott
Basically, I type 'python' into Git Bash command line and I get back a blank line as if the command line is thinking...
基本上,我在 Git Bash 命令行中键入“python”,然后返回一个空行,就好像命令行在思考……
I've done plenty of research but I can't seem to run python on Git Bash by typing in python into the command line. I was looking at Python not working in the command line of git bashand someone recommended to type: winpty c:/Python34/python.exe into the command line and it worked! However, I dont want to have to keep typing that entire command into the command line. Can someone help?
我已经做了大量的研究,但我似乎无法通过在命令行中输入 python 在 Git Bash 上运行 python。我正在查看Python 在 git bash 的命令行中不起作用,有人建议在命令行中键入:winpty c:/Python34/python.exe 并且它起作用了!但是,我不想一直在命令行中输入整个命令。有人可以帮忙吗?
回答by hansmosh
A few of the solutions hereshould help you out.
这里的一些解决方案应该可以帮助你。
Or, as @adarsh suggests, add the following to ~/.bashrc (or in ~/.bash_profile if this doesn't work for your version of Git Bash):
或者,正如@adarsh 所建议的那样,将以下内容添加到 ~/.bashrc (如果这不适用于您的 Git Bash 版本,则添加到 ~/.bash_profile 中):
PATH=$PATH:c/Python34/
回答by apeke
"One caveat if using Git Bash with MinTTY: python doesn't go into interactive mode so a solution is to force it to start that way: echo alias python=\"python -i\" >> ~/.bash_profile"]
“如果将 Git Bash 与 MinTTY 一起使用,请注意:python 不会进入交互模式,因此解决方案是强制它以这种方式启动:echo alias python=\"python -i\" >> ~/.bash_profile"]
I had the same issue and using "python -i" solved it.
我遇到了同样的问题,使用“python -i”解决了它。
回答by just call me
If you have two version of Python installed I would just point exe independently. example:
如果您安装了两个版本的 Python,我会单独指向 exe。例子:
$ '/d/Python 3.6.4/python.exe' /d/1.APPS/gitHUBprojects/project1/project1.py
$ '/d/Python 3.6.4/python.exe' /d/1.APPS/gitHUBprojects/project1/project1.py
回答by Dave
The comment of adding it to the .bashrc is likely the best answer.
将它添加到 .bashrc 的评论可能是最好的答案。
Type:
类型:
- open terminal
- cd ~ (hit enter)
- vim .bashrc (hit enter)
- Hit I to insert on one of the lines and type:
- alias python3='c:/Python34/python.exe'
- hit esc (enters vim command mode)
- type :wq (write and quit)
- hit enter
- 打开终端
- cd ~(按回车键)
- vim .bashrc(按回车键)
- 点击 I 插入其中一行并输入:
- 别名 python3='c:/Python34/python.exe'
- 按 esc(进入 vim 命令模式)
- 输入:wq(写入并退出)
- 按回车
Now type python3 in gitbash hit enter and there you go!
现在在 gitbash 中输入 python3 按回车键就可以了!
回答by Mindputty
Since you were asking specifically about needing to type it again and again, you'll probably want to create an alias in your .bashrc or .bash_profile file:
由于您专门询问是否需要一次又一次地键入它,因此您可能希望在 .bashrc 或 .bash_profile 文件中创建一个别名:
alias python="winpty C:/Python34/python.exe"
alias python="winpty C:/Python34/python.exe"
回答by AronGahagan
@Mindputty's answer above worked best for me -- in .bash_profile
-- with the addition of the -i
option:
@Mindputty 上面的回答对我来说效果最好——在.bash_profile
——加上-i
选项:
alias py="winpty C:/Python38/python.exe -i"
Also added:
还补充道:
alias py="winpty C:/Python38/python.exe -i"
I'm on Windows 10 (64-bit) with git-for-windows 2.25.windows.1 and python 3.8.2.
我在 Windows 10(64 位)上使用 git-for-windows 2.25.windows.1 和 python 3.8.2。
(@Mindputty - sorry, don't have enough cred to upvote. But thank you--this was driving me crazy.)
(@Mindputty - 抱歉,没有足够的信誉来投票。但是谢谢你 - 这让我发疯了。)