Git Bash won't run my python files?
Solution 1
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.
Solution 2
That command did not work for me, I used:
$ export PATH="$PATH:/c/Python27"
Then to make sure that git remembers the python path every time you open git type the following.
echo 'export PATH="$PATH:/c/Python27"' > .profile
Solution 3
Here is the SOLUTION
If you get Response:
bash: python: command not found
ORbash: conda: command not found
To the following Commands:
when you execute python
or python -V
conda
or conda --version
in your Git/Terminal window
Background: This is because you either
- Installed Python in a location on your C Drive (C:) which is not directly in your program files folder.
- Installed Python maybe on the D Drive (D:) and your computer by default searches for it on your C:
- You have been told to go to your environment variables (located if you do a search for environment variables on your machines start menu) and change the "Path" variable on your computer and this still does not fix the problem.
Solution:
At the command prompt, paste this command
export PATH="$PATH:/c/Python36"
. That will tell Windows where to find Python. (This assumes that you installed it in C:\Python36)If you installed python on your D drive, paste this command
export PATH="$PATH:/d/Python36"
.Then at the command prompt, paste
python
orpython -V
and you will see the version of Python installed and now you should not getPython 3.6.5
Assuming that it worked correctly you will want to set up git bash so that it always knows where to find python. To do that, enter the following command:
echo 'export PATH="$PATH:/d/Python36"' > .bashrc
Permanent Solution
Go to BASH RC Source File (located on C: / C Drive in “C:\Users\myname”)
Make sure your BASH RC Source File is receiving direction from your Bash Profile Source File, you can do this by making sure that your BASH RC Source File contains this line of code: source ~/.bash_profile
Go to BASH Profile Source File (located on C: / C Drive in “C:\Users\myname”)
Enter line: export PATH="$PATH:/D/PROGRAMMING/Applications/PYTHON/Python365" (assuming this is the location where Python version 3.6.5 is installed)
This should take care of the problem permanently. Now whenever you open your Git Bash Terminal Prompt and enter “
python
” or “python -V
” it should return the python version
Solution 4
When you install python for windows, there is an option to include it in the path. For python 2 this is not the default. It adds the python installation folder and script folder to the Windows path. When starting the GIT Bash command prompt, it have included it in the linux PATH variable.
If you start the python installation again, you should select the option Change python and in the next step you can "Add python.exe to Path". Next time you open GIT Bash, the path is correct.
Related videos on Youtube
user3496571
Updated on July 09, 2022Comments
-
user3496571 almost 2 years
I have been trying to run my python files in Git Bash but I keep getting an error and can't figure out how to fix it. My command as follows in the git bash executable
python filename.py
then it says"Bash.exe": python.exe: command not found
I'm a windows user and I have added the path to my environment variables like so
C:\Python27\python.exe;C:\Program Files\Git\bin\bash.exe
I have been looking around but I can't find anyone that has had this problem or they don't give a straightforward answer please help.
Also I have never used Git before this is my first time.
-
tlehman about 10 yearsCould you type
echo $PATH
and paste the results? You may be using the Windows Environment variables instead of the ones that Bash recognizes -
Wooble about 10 yearsYour PATH should contain the directories containing your executables, not the executables themselves.
-
Admin about 10 yearspossible duplicate of Adding Python Path on Windows 7
-
Sterling over 2 yearsIf you run
python
in the terminal, it should (now) come up with the Windows Store app installation page.
-
-
Green almost 8 yearsNo it doesn't work. It is not enough to have Python executable dir in PATH. It still doesn't work
-
gturri almost 8 years@Green: Given the number of upvotes, I'd say that it might have been pretty effective so far. ie: I think you're in a particular case here (custom bash? python installed in a path with whitespaces?). Hence I'd suggest you ask a new question, so you'll be able to give as much details as possible, in order to get a more accurate reply for your particular case
-
CoffeeTableEspresso almost 5 yearsthis works for me. Any way to automatically do this every time I open up git bash instead of having to rewrite this every time? EDIT: other answer below explains how to add to bash rc
-
Jeremy Thompson over 4 yearsYes, thank you I had created a .bashrc file in my C:\Users<imID>\. I deleted it and restarted GitBash and commands started working again. Not sure who downvoted this but appreciate you not deleting this!