4

I have python 3.6 installed on my Win7 system and am trying to get it working in the git bash (MINGW64), so far to no avail.

I've added the install directory (NOT the .exe, of course) to PATH, with no results.

Even if I directly cd to the install directory, it doesn't see it.

$ python
bash: python: command not found
$ echo $PATH
/c/Users/Aerovistae/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/Users/Aerovistae/bin:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program Files/Intel/WiFi/bin:/c/Program Files/Common Files/Intel/WirelessCommon:/cmd:/c/Program Files (x86)/Skype/Phone:/c/Program Files/Intel/WiFi/bin:/c/Program Files/Common Files/Intel/WirelessCommon: C:/Users/Aerovistae/AppData/Local/Programs/Python/Python36-32:/usr/bin/vendor_perl:/usr/bin/core_perl
$ cd C:/Users/Aerovistae/AppData/Local/Programs/Python/Python36-32
$ python
bash: python: command not found
$ python.exe
bash: python.exe: command not found

If I try ./python from inside that directory, it just goes to the next line when I hit enter, and allows me to keep typing because it's expecting more to the command for some reason. ./python isn't being recognized as a complete command, and it is waiting for closure, as if I had an open-quote but no close-quote. Can't figure out why.

What am I missing here? Why can't it run the .exe even when I'm in the directory?

Sidenote, why does it show PATH as having colon separators rather than semi-colon separators?

temporary_user_name
  • 35,956
  • 47
  • 141
  • 220

2 Answers2

9

why does it show PATH as having colon separators rather than semi-colon separators?

Because bash uses : as a path separator. This means that C:/yadda/yadda in your PATH environment variable is parsed as two directories: C and /yadda/yadda. If you look closely at your echo $PATH output you will see that many entries start with /c/. The entry for your python installation is the only one which uses C:/. You should use the /c/ notation when setting PATH in .bashrc or .profile.

Also be careful about spaces in path names and extraneous spaces before and after :. The former is definitely problematic. I am not certain about the latter since I never add spaces in this location when setting PATH.

If I try ./python from inside that directory, it just goes to the next line when I hit enter, and allows me to keep typing because it's expecting more to the command for some reason. 

Per the comment from @eryksun:

You either need to run bash.exe in a normal Windows console or, if using the mintty terminal, force Python to use interactive mode via python -i. mintty hides the real console and sets StandardInput to a pipe named \\.\pipe\msys-[UNIQUE_ID]-pty0-from-master and StandardOutput to a pipe named \\.\pipe\msys-[UNIQUE_ID]-pty0-to-master. A pipe is not a character device in Windows, so isatty returns false, so Python starts in non-interactive mode unless forced otherwise via the -i option.

Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268
  • Forgot to mention that sadly I did this as well--- for the record I am passably familiar with the linux command line. It just hangs, goes to next line with blinking cursor when I hit enter, like it's expecting more input and `./python` isn't recognized as a valid standalone command. Have to ctrl+c out of it. – temporary_user_name Jan 06 '17 at 03:55
  • @Aerovistae it will also help if you show `pwd` before each command – Code-Apprentice Jan 06 '17 at 03:59
  • I considered adding that but it made it very cluttered since the output is long. Fwiw I assure you it is the directory I `cd`'d into. I run `pwd` out of paranoia when these things happen, but there was nothing to see. – temporary_user_name Jan 06 '17 at 04:01
  • @Aerovistae see my new answer – Code-Apprentice Jan 06 '17 at 04:05
  • @Aerovistae the main point about `pwd` is that it will show you your own mistakes, particularly after a `cd`. – Code-Apprentice Jan 06 '17 at 04:21
  • True, but with regards to the updated answer I don't think this is the problem-- it's definitely in the right directory. `ls` after `cd` shows all the correct contents of my python installation folder. – temporary_user_name Jan 06 '17 at 04:37
  • 3
    In addition to fixing the `PATH` in bash as this answer suggests, you either need to run bash.exe in a normal Windows console or, if using the mintty terminal, force Python to use interactive mode via `python -i`. mintty hides the real console and sets `StandardInput` to a pipe named `\\.\pipe\msys-[UNIQUE_ID]-pty0-from-master` and `StandardOutput` to a pipe named `\\.\pipe\msys-[UNIQUE_ID]-pty0-to-master`. A pipe is not a character device in Windows, so `isatty` returns false, so Python starts in non-interactive mode unless forced otherwise via the `-i` option. – Eryk Sun Jan 06 '17 at 05:35
  • @eryksun you should post this as an answer – Code-Apprentice Jan 06 '17 at 06:11
  • @Aerovistae granted, this might not be the only problem, but it will solve the "command not found" issues – Code-Apprentice Jan 06 '17 at 06:12
  • With regards to command not found-- this suggests that it would be able to run it if it could find it on the path. But I can't even run it when I'm in the installation directory itself. Doesn't that imply a different issue? Also not really clear how I can change `PATH` for bash without changing it for the entire system. – temporary_user_name Jan 06 '17 at 07:14
  • Also that just seems bizarre.....the shell is designed for windows, but doesn't convert windows paths to bash-compatible formats for itself? That can't be right. I mean obviously even before I added Python, the path was full of sub-paths using `C:/` – temporary_user_name Jan 06 '17 at 07:31
  • @Aerovistae you can set PATH for only bash by editing `~/.bashrc` or `~/.profile`. This will not affect the rest of Windows. You can, in fact, run from the installation directory. You said yourself that `./python` does not produce the "command not found" error. Without `./` does not work because `.` is not in PATH, as is correct in a bash environment. See eryksun's comment. Also, none of the other elements in PATH use the `C:/` notation. They all use `/c/` instead. – Code-Apprentice Jan 06 '17 at 10:16
  • Sure enough `-i` lets me run python from inside the directory. Just need to conclude this `PATH` issue now. Here's the thing: when I `echo $PATH`, *all* of the components use the correct `/c/` notation EXCEPT python-- hence python isn't working, of course. Makes sense. But if I go to Environment Variables and look at path.....everything there uses the `C:/` notation. So why is git bash correctly reformatting each path for itself except python's? – temporary_user_name Jan 07 '17 at 21:53
  • @Aerovistae How did you install python? How did its install directory get added to the path? – Code-Apprentice Jan 08 '17 at 03:47
  • The normal way, the msi off their website. Yes, the directory on path is indeed the directory python is installed to. – temporary_user_name Jan 08 '17 at 04:36
  • @Aerovistae please be more specific. I have not used windows for years. – Code-Apprentice Jan 08 '17 at 04:38
  • I installed it using the executable installer that you get if you click Download on either version on the [main download page.](https://www.python.org/downloads/) – temporary_user_name Jan 08 '17 at 06:49
4

try using this command on your git bash: alias python='winpty python.exe If you can use Python normally and you can output and input without problems you can add that command in your .bashrc configuration file (usually in the same directory of your .git and .mintty configuration files (under your username on Windows).

I don't know what winpty actually does but I guess it's what it's described here: https://github.com/rprichard/winpty

Luca
  • 85
  • 1
  • 10