Richard Tweeddale
Richard Tweeddale

Reputation: 504

bash looking in wrong place for python executable

Whenever I try to run a python command using the Git Bash terminal on Windows, it looks in the wrong place:

$ python --version
C:/Program Files/Git/usr/bin/python.exe: error while loading shared libraries: 
?: cannot open shared object file: No such file or directory

The folder containing the python executable has been added to the PATH variable:

$ $PATH
bash: /mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/f/bin:/c/_Programming/Python/Installation/Python36-32/Scripts:/c/_Programming/Python/Installation/Python36-32:/c/_Programming/Ruby/Installation/RailsInstaller/Git/cmd:/c/_Programming/Ruby/Installation/RailsInstaller/Ruby2.3.0/bin:/cmd:/usr/bin/vendor_perl:/usr/bin/core_perl: No such file or directory

I don't understand why the Git Bash terminal is looking for python in a location that's not in the PATH. Accessing python from the Windows terminal works just fine:

C:\Windows\System32>python --version
Python 3.6.2

How can I get Git Bash to use the correct location for python?

Upvotes: 2

Views: 3413

Answers (2)

mrcrow85
mrcrow85

Reputation: 72

The git bash and Windows console are two completely different command line programs. Git bash is a Linux based terminal (with its own set of libraries) ported to Windows, so in order for git bash to know where a program is, you must do it manually. I mean, you have to also set the PATH variable in git bash. This article explains how to do it. In short this is what you need to do:

  1. Launch the program Git Bash in the usual way that you launch Windows programs. A shortcut for Git Bash was created during installation.
  2. At the command prompt, paste this command export PATH="$PATH:/c/Python27". That will tell Windows where to find Python. (This assumes that you installed it in C:\Python27, as we told you to above.)
  3. Check to make sure that this worked correctly by entering the command python --version. It should say Python 2.7.8 (or 2.7.something), as shown in the figure below.
  4. Assuming that 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:/c/Python27"' > .bashrc. That will save the command into a file called .bashrc. .bashrc is executed every time git bash launches, so you won’t have to manually tell the shell where to find python again.
  5. Check to make sure that worked by typing exit, relaunching git bash, and then typing python --version again.

Upvotes: 4

rohit2219
rohit2219

Reputation: 248

My guess is that the Git usr/bin directory :/usr/bin has a python executable, which is getting read first before your /c/_Programming/Python/Installation/Python36-32/Scripts, ( I assume that where you have installed your python exec). Try changing the PATH to prefix /c/_Programming/Python/Installation/Python36-32/Scripts

Upvotes: 2

Related Questions