Git Bash won't run my python files?

146,274

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:

  1. bash: python: command not found OR
  2. 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

  1. Installed Python in a location on your C Drive (C:) which is not directly in your program files folder.
  2. Installed Python maybe on the D Drive (D:) and your computer by default searches for it on your C:
  3. 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:

  1. 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)

  2. If you installed python on your D drive, paste this command export PATH="$PATH:/d/Python36".

  3. 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

  4. 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

  1. Go to BASH RC Source File (located on C: / C Drive in “C:\Users\myname”)

  2. 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

  3. Go to BASH Profile Source File (located on C: / C Drive in “C:\Users\myname”)

  4. Enter line: export PATH="$PATH:/D/PROGRAMMING/Applications/PYTHON/Python365" (assuming this is the location where Python version 3.6.5 is installed)

  5. 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.

Share:
146,274

Related videos on Youtube

user3496571
Author by

user3496571

Updated on July 09, 2022

Comments

  • user3496571
    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
      tlehman about 10 years
      Could you type echo $PATH and paste the results? You may be using the Windows Environment variables instead of the ones that Bash recognizes
    • Wooble
      Wooble about 10 years
      Your PATH should contain the directories containing your executables, not the executables themselves.
    • Admin
      Admin about 10 years
      possible duplicate of Adding Python Path on Windows 7
    • Sterling
      Sterling over 2 years
      If you run python in the terminal, it should (now) come up with the Windows Store app installation page.
  • Green
    Green almost 8 years
    No it doesn't work. It is not enough to have Python executable dir in PATH. It still doesn't work
  • gturri
    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
    CoffeeTableEspresso almost 5 years
    this 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
    Jeremy Thompson over 4 years
    Yes, 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!