Python 3 won't run from the Git Bash command line

27,898

Solution 1

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

Solution 2

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/

Solution 3

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

Solution 4

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

Solution 5

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!

Share:
27,898
Admin
Author by

Admin

Updated on July 09, 2022

Comments

  • Admin
    Admin almost 2 years

    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.

  • Kevin Burdett
    Kevin Burdett over 8 years
    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.
  • dubes
    dubes over 5 years
    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.