Git Bash won't run my python files?
Adapting the PATH
should work. Just tried on my Git bash:
$ python --version
sh.exe": python: command not found
$ PATH=$PATH:/c/Python27/
$ python --version
Python 2.7.6
In particular, only provide the directory; don't specify the .exe
on the PATH
; and use slashes.
How to use python on gitbash
Getting python run in git bash you simply can type winpty python
or you can use python -i
Note: if you use winpty python
you can exit python with CTRL + Z
or exit()
, but if you used python -i
, you only can exit with exit()
.
Why does asyncio work in cmd but not in Git Bash?
Per Mofi's comment, I changed my code to this:
import asyncio
async def main():
print('hello', flush=True)
await asyncio.sleep(3)
print('world', flush=True)
asyncio.run(main())
This forces the buffer to flush after both prints, sending it to the terminal. It works in Git Bash now.
Details:
From what I now understand, under the hood, python sets the buffering depending on the detected device. From https://docs.python.org/2/library/functions.html#open, files are "usually line buffered for tty devices and fully buffered for other files". Print uses the default sys.stdout file object to write to.
Running a new module with the following code:
import sys
print(f'{sys.stdout.isatty()=}')
It prints 'sys.stdout.isatty()=True' in cmd but 'sys.stdout.isatty()=False' in git bash, which explains why stdout chooses to fully buffer in git bash, not print until the code exits, and line buffers in cmd.
Related Topics
How to Merge Elements in List in Python With Condition
How to Make an Auto Increment Integer Field in Django
How to Write a Lambda Function That Is Conditional on Two Variables (Columns) in Python
Cannot Convert the Series to <Class 'Int''>
How to Save Opened Page as Pdf in Selenium (Python)
Efficient Date Range Overlap Calculation
Get All the Diagonals in a Matrix/List of Lists in Python
Adding Columns to Dataframe Based on File Name in Python
How to Calculate Rolling/Moving Average Using Python + Numpy/Scipy
How to Properly Redirect Stdout/Stderr from a Systemd Service on Raspbian
Compare a Column Between 2 CSV Files and Write Differences Using Python
Check If Dataframe Has a Zero Element
Python How to Remove Escape Characters from a String
Pandas To_Csv: Suppress Scientific Notation in CSV File When Writing Pandas to Csv
Anaconda Installed But Cannot Launch Navigator
Is There an Easy Way in Python to Wait Until Certain Condition Is True
Why Is Python No Longer Waiting for Os.System to Finish
Loop Over List of Elements for Find_Element_By_Xpath() by Selenium and Webdriver