14

Basically, I type python into Git Bash command line and I get back a blank line as if the command line is thinking...

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 the question: Python not working in the command line of git bash and someone recommended to type:

winpty c:/Python34/python.exe

into the command line and it worked! However, I don't want to have to keep typing that entire command into the command line.

3
  • I would assume adding it to ~/.bashrc would make it work each time. Commented Feb 18, 2016 at 1:43
  • 1
    A few of the solutions here should help you out. Commented Feb 18, 2016 at 1:49
  • 1
    Does this answer your question? Python not working in the command line of git bash (I see that you found that question already; but note that (at the moment of writing) there are some solutions there that use alias and that is permanent) Commented Aug 16, 2021 at 13:51

6 Answers 6

7

"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"]

For more details

I had the same issue and using "python -i" solved it.

Sign up to request clarification or add additional context in comments.

Comments

4

The comment of adding it to the .bashrc is likely the best answer.

Type:

  1. open terminal
  2. cd ~ (hit enter)
  3. vim .bashrc (hit enter)
  4. Hit I to insert on one of the lines and type:
  5. alias python3='c:/Python34/python.exe'
  6. hit esc (enters vim command mode)
  7. type :wq (write and quit)
  8. hit enter

Now type python3 in gitbash hit enter and there you go!

1 Comment

you might want to add a 9th step: source ~/.bashrc or quit and reopen terminal, else you might not see the alias in your terminal.
3

A few of the solutions here should 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):

PATH=$PATH:c/Python34/

1 Comment

bonus: if you add it to your Windows path (system or user) rather than in your .bashrc, then it will be usable from both cmd.exe and git bash, as git bash will respect your environment path.
2

If you have two version of Python installed I would just point exe independently. example:

$ '/d/Python 3.6.4/python.exe' /d/1.APPS/gitHUBprojects/project1/project1.py

Comments

2

@Mindputty's answer above worked best for me -- in .bash_profile -- with the addition of the -i option:

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.

(@Mindputty - sorry, don't have enough cred to upvote. But thank you--this was driving me crazy.)

Comments

0

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:

alias python="winpty C:/Python34/python.exe"

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.