13

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.

user202729
  • 3,358
  • 3
  • 25
  • 36
Scott
  • 131
  • 1
  • 1
  • 3
  • I would assume adding it to [~/.bashrc](http://stackoverflow.com/a/6883798/1068887) would make it work each time. – adarsh Feb 18 '16 at 01:43
  • 1
    A few of the solutions [here](http://stackoverflow.com/a/10764080/3079347) should help you out. – hansmosh Feb 18 '16 at 01:49
  • 1
    Does this answer your question? [Python not working in the command line of git bash](https://stackoverflow.com/questions/32597209/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) – user202729 Aug 16 '21 at 13:51

6 Answers6

6

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

Avinash Singh
  • 4,970
  • 8
  • 20
  • 35
apeke
  • 61
  • 1
  • 1
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!

kuskmen
  • 3,648
  • 4
  • 27
  • 54
Dave
  • 41
  • 1
  • 3
    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. – dubes Aug 31 '18 at 08:58
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/
Community
  • 1
  • 1
hansmosh
  • 491
  • 5
  • 13
  • 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. – Kevin Burdett Feb 18 '16 at 02:02
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

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.)

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"

Mindputty
  • 1
  • 5