Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

windows - Can't run python in git terminal?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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 \.pipemsys-[UNIQUE_ID]-pty0-from-master and StandardOutput to a pipe named \.pipemsys-[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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

57.0k users

...