I'm currently trying to add a git extension (or plug-in, whatever you want to call it) to the CLI on windows, so if I typed git hello
, it would execute a hello world program for example.
The hello world program (in python) is below. This works perfectly fine on Unix systems.
#!/usr/bin/env python
print ("Hello GIT!")
If I put the file in my path, and name it "git-hello" it should execute when I call "git hello". The file doesn't have an extension as it'd make the command "git hello.py" which is undesirable and also fails in the same way.
However, GIT is having a bit of trouble with the environment line and spits out the following:
PS D:\GitTests> git hello
/usr/bin/env: 'python': No such file or directory
Things I've tried are:
- Changing "python" to be "py", as that's how my python interpreter launches on the CLI. This just causes the entire thing to hang and do nothing.
- Changing the environment line to be the direct path to the executable for python.
I know that you can use the git config
method (so it'd be git config --global alias.hello "!py D:/GitTests/git-hello.py" in my case), however I don't think that seems like the best way to do things, as on windows you need supply the python interpreter in the alias.
So my question is - How do you get python programs (such as the above one) to execute with GIT on Windows?
Edit: The suggested duplicate does not address the problem here as it was to do with file association on the command line, but the issue for this question was that python was not correctly in the path.
For those encountering similar issues and installed python via 2017 - ensure your path is correct. VS Installer did not add python to my path, but instead some variant that had only py.exe and not python.exe in the path.