Running a python script from Git Bash for Windows

17,575 views
Skip to first unread message

rdharles

unread,
Apr 24, 2018, 9:40:07 AM4/24/18
to git-for-windows
Hi,
I'd like to run a python script without typing the full path to the script location.  It would also be nice not to have to type "python" before the script name.

I'm able to type python and go into the interpreter so we know bash know the path to python.exe:




When I type the name of the script, it doesn't run, but as you can see it knows where the path to the script location:




With "python" in front of the script name, it still doesn't work despite bash knowing where the script is:



It will work if you type "python" and then the full path to the script:




Any thoughts on how I can get this to work?
Thank for any ideas you have!
R.D.  Harles

Nate Hansen

unread,
Apr 26, 2018, 8:03:45 AM4/26/18
to git-for-windows
A short workaround may be to put a ./ before the script name to signal that it is in the current directory. It sounds like an issue with python not accepting the current working directory. Could bash be passing in a Posix path instead of a Windows one?

rdharles

unread,
Apr 26, 2018, 8:25:42 AM4/26/18
to git-for-windows
Thanks for taking the time to respond.  I'll look into Posix path vs. Windows path.

Johannes Schindelin

unread,
Apr 27, 2018, 8:34:08 AM4/27/18
to rdharles, git-for-windows
It could also be an extra Carriage Return in the shebang line (MSYS2's
Runtime expects Unix line endings, not Windows ones).
> --
> You received this message because you are subscribed to the Google Groups "git-for-windows" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to git-for-windo...@googlegroups.com.
> To post to this group, send email to git-for...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/git-for-windows/759cbce9-caa8-430c-b167-e918ca477638%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
Message has been deleted

rdharles

unread,
Apr 27, 2018, 9:26:39 AM4/27/18
to git-for-windows
I played around with the shebang line and these 2 versions both worked for my setup...

#!python  or  #!/usr/bin/env python

 
Thanks for your response.

kudzai zoraunye

unread,
Dec 3, 2022, 3:12:26 PM12/3/22
to git-for-windows
the 2nd shebang worked for me

Prashant Kumar Singh

unread,
Dec 19, 2023, 4:18:36 PM12/19/23
to git-for-windows
Thanks, your answer was helpful.
Reply all
Reply to author
Forward
0 new messages