I was recently running a python test program in gitbash. It looks like this:
COST_OF_FRISBEE = 15
num_frisbees = int(input("How many frisbees do you want? "))
result = COST_OF_FRISBEE * num_frisbees
print("The total cost is " + str(result))
and is saved in a file called hw4.py. Unfortunately, when I run the program with the command python3 hw4.py
, and type in a number as the program prompts me to, gitbash hangs after I press the enter key on my keyboard. It actually allows me to keep hitting enter multiple times and to continue typing things in. I've screenshotted what this looks like:
The screenshot was taken after the following was entered from my keyboard: python3 hw4.py
, return, 3
, return (3 times), asdf
, up arrow key (5 times), Backspace (4 times). You can see from the screenshot that gitbash lets me delete part of the filepath prompt (which should never happen), confusing me greatly. I have also tried ctrl-C'ing and ctrl-D'ing out of it, but nothing happens. The only way to get out of it is to close the whole window out, during which attempt I get a pop-up warning me that there is an ongoing process that I will have to kill. I've tried googling this but the only search results I get are that the command 'python3' isn't recognized on the command line, which is a totally different problem.
Please help! Thanks!
EDIT: I tried the same thing on my computer at home (the original problem occurred on my work laptop) and found something interesting that makes me think that this has to do with my installation of Python, rather than anything to do with buffer flushing. In the following screenshot you can see that when I simply type 'python' and follow the same keystrokes that I described above, I get the same hanging behavior that is so annoying:
This, however, only happens when my .bashrc file looks like this:
export PATH="$PATH:/c/PATH_TO_PYTHON/Python/Python310 : /c/PATH_TO_PYTHON/Python/Python310/Scripts"
When my .bashrc looks like this, instead...
export PATH="$PATH:/c/PATH_TO_PYTHON/Python/Python310 : /c/PATH_TO_PYTHON/Python/Python310/Scripts"
alias python="winpty python.exe"
...I am able to enter the python interpreter, and that works normally, even though it's not what I want. To be clear, I want to be able to run my python file with the command "python3 hw4.py" or "python hw4.py" directly from the gitbash CLI. I've been able to do this in the past, so I know it's possible!
As a last note, if you're trying to reproduce the issue, make sure to close out your gitbash session after you edit the .bashrc file so that your changes from the edit can take effect.
Thanks again for the help.