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.
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.
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
Here is the SOLUTION
If you get Response:
bash: python: command not found
OR bash: 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
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
or python -V
and you will see the version of Python installed and now you should not get Python 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
Add following line in you .bashrc file
############################
# Environment path setting #
############################
export PATH=/c/Python27:/c/Python27/Scripts:$PATH
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.
Tried multiple of these, I switched to Cygwin instead which fixed python and some other problems I was having on Windows:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.