git bash의 명령 줄에서 Python이 작동하지 않습니다.
파이썬은 git bash (Windows)에서 실행되지 않습니다. 명령 줄에 python을 입력하면 Powershell에서와 같이 2.7.10으로 python 2.7.10을 입력했다고 말하지 않고 빈 줄로 이동합니다. 그것은 나에게 오류 메시지를주지 않지만 파이썬은 실행되지 않습니다.
PATH의 환경 변수가 이미 포함되어 있는지 확인했습니다 c:\python27
. 다른 무엇을 확인할 수 있습니까?
이 문제가 발생하는 세션은 다음과 같습니다.
user@hostname MINGW64 ~
$ type python
python is /c/Python27/python
user@hostname MINGW64 ~
$ python
... 프롬프트로 돌아 가지 않고 앉아 있습니다.
windows->의 git shell에 이것을 입력하면됩니다 alias python='winpty python.exe'
. 파이썬 실행 파일의 별칭이 있습니다. 즐겨
PS 영구적 인 별칭 추가는 아래를 참조하십시오.
cd ~
touch .bashrc
그런 다음 .bashrc를 열고 위에서 명령을 추가하고 파일을 저장하십시오. 콘솔을 통해 파일을 작성해야하거나 올바른 이름으로 저장할 수 없습니다. 변경 사항을 적용하려면 셸을 다시 시작해야합니다.
답변 목록에 다음 옵션이 표시되지 않지만 "-i"키를 사용하여 대화식 프롬프트를 얻을 수 있습니다.
$ python -i
Python 3.5.2 (v3.5.2:4def2a2901a5, Jun 25 2016, 22:18:55)
Type "help", "copyright", "credits" or "license" for more information.
>>>
이것은 MSys2에서 알려진 버그이며 Git Bash가 사용하는 터미널을 제공합니다. ncurses를 지원하지 않고 Python 빌드를 실행하거나 다음과 같이 WinPTY 를 사용 하여이 문제 를 해결할 수 있습니다.
mintty 또는 Cygwin sshd에서 Windows 콘솔 프로그램을 실행하려면 console.exe를 명령 줄 앞에 추가하십시오.
$ build/console.exe c:/Python27/python.exe Python 2.7.2 (default, Jun 12 2011, 15:08:59) [MSC v.1500 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> 10 + 20 30 >>> exit()
MSYS에 대한 사전 구축 된 바이너리 힘내 배쉬와 일 가능성이 높다. (이 답변이 게시 된 후 상당한 시간이 지난 경우 최신 버전이 있는지 확인하십시오!).
Git for Windows 2.7.1부터는 winpty c:Python27/python.exe
; WinPTY는 기본적으로 포함되어있을 수 있습니다.
저는 Windows 10 사용자이며 기본값을 그대로 사용하여 시스템에 GIT 를 설치 했습니다.
위의 답변을 읽은 후, 나는 내 자신에 대한 2 개 솔루션을 가지고 이러한이 개 솔루션은 완벽하게 작동 GIT의 떠들썩한 파티와 파이썬 문 실행하기 위해 저를 용이하게 GIT의 bash는.
내 GIT bash 터미널의 이미지 3 개를 첨부하고 있습니다. 첫 번째는 문제가 있고 두 번째는 솔루션입니다.
문제 - python
명령을 누른 후 커서가 대기 중입니다.
솔루션 1
GIT bash 터미널 winpty <path-to-python-installation-dir>/python.exe
에서 실행하십시오 .
참고 : GIT bash C:\Users\Admin
에서 같은 경로 스타일을 사용하지 말고 대신을 사용하십시오 ./C/Users/Admin
제 경우에는 GIT bash에서 winpty /C/Users/SJV/Anaconda2/python.exe
명령을 실행했습니다.
또는 사용자 이름 을 모르는 경우 실행하십시오.winpty /C/Users/$USERNAME/Anaconda2/python.exe
솔루션 2
입력 만하면 python -i
됩니다.
감사.
@ Charles-Duffy의 답변 외에도 추가 항목을 설치 / 다운로드하지 않고 winpty를 직접 사용할 수 있습니다. 그냥 실행하십시오 winpty c:/Python27/python.exe
. winpty.exe 유틸리티는 Git \ usr \ bin에 있습니다. Windows v2.7.1에 Git을 사용하고 있습니다
@ Charles-Duffy의 사전 빌드 바이너리는 버전 0.1.1 (파일 이름에 따름)이고 포함 된 바이너리는 0.2.2입니다.
시도 python -i
대신에 python
, 그것은 커서 일입니다.
Git Bash Workaround- Launch Python 2 & Python 3 with aliases
HI. This is (for me) the best solution to run both Python (Python 2.7 and Python 3.x) directly from Git Bash on Win 10 => adding aliases into the aliases file that Git Bash uses for.
Git Bash aliases file is aliases.sh. It is located in:
C:\path where you installed Git\etc\profile.d\aliases.sh
1) Open (with a text editor like Atom or other) the aliases.sh
for ex: in my case the file is in C:\Software\Develop\Git\etc\profile.d\aliases.sh
2) Add your alias for Python
In my case the python.exe are installed in:
C:\Networking\Network Automation\Python 2.7\python.exe
C:\Networking\Network Automation\Python 3.7\python.exe
So you must create 2 aliases, one for Python 2 (I named python2) and the other for Python 3 (I named just python) Git Bash uses linux file structure so you need to change the "\" for "/" and if you have a path like my example Network Automation you put it with " "
"Network Automation", for ex.
winpty is the magic command that will call the executable.
So add these lines at the beginning of aliases.sh
alias python2='winpty C/Networking/"Network Automation"/"Python 2.7"/python.exe'
alias python='winpty C/Networking/"Network Automation"/"Python 3.7"/python.exe'
3) Add or Modify other aliases (if you want)
I modified also the ll alias to show all the files and in a human readable list:
alias ll='ls -lah'
4) Save the aliases.sh file
5) OK!!! close and relaunch your Git Bash
Now, permanently you could launch both Python directly from Git shell just writting
$ python
-> launch Python 3
$ python2
-> launch Python 2
$ ll
-> enters a ls -lah to quickly show your detailed file list
Cheers, Harry
type: 'winpty python' and it will work
gitbash has some issues when running any command that starts with python. this goes for any python manage.py commands as well. Always start with 'winpty python manage.py' At least this is what works for me. Running Windows 10.
In addition to @Vitaliy Terziev answer
try touch .bash_profile
and then add alias into the file.
You can change target for Git Bash shortcut from:
"C:\Program Files\Git\git-bash.exe" --cd-to-home
to
"C:\Program Files\Git\git-cmd.exe" --no-cd --command=usr/bin/bash.exe -l -i
This is the way ConEmu used to start git bash (version 16). Recent version starts it normally and it's how I got there...
I am using MINGW64 via Visual Studio Code on Windows 10 and trying to install node-sass
(which requires python2
). I followed felixrieseberg/windows-build-tools #56 on Github which solved my issue.
This is a special case, but I'm posting in case someone has the same problem:
npm --add-python-to-path='true' --debug install --global windows-build-tools
This installs python and other required build tools to %USERPROFILE%\.windows-build-tools\python27
.
Another example of this issue is using the AWS Elastic Beanstalk command line interface (awsebcli, eb cli) from the git bash (MINGW64, Mintty) in windows (using git version 2.19.0.windows.1).
I'm just posting this because it took me a while to end up here, searching for eb-cli
specific issues.
Commands such as eb init
or eb config save
, which require user input, appear to cause a freeze/hang. In reality I guess the console is not updated with the text requesting user input. Moreover, eb deploy
only updates the console text after the command has finished, so I don't get to see progress updates until finished.
As mentioned in the git for windows release notes (for v2.19.0) and e.g. in Xun Yang's answer, a workaround is to run
winpty eb <command>
(instead of just eb <command>
)
A alternative, as suggested in this git for windows issue, could be to use the windows native console instead of mintty (option during git installation).
gitbash를 기본 터미널로 사용하는 vscode의 Python 버전 3.7.3의 경우이 문제를 잠시 처리 한 다음 @Vitaliy Terziev의 .bashrc에 별칭을 추가하는 다음 조언을 따랐습니다.
alias python = '“/ c / Users / 내 사용자 이름 /AppData/Local/Programs/Python/Python37/python.exe”'
“내 사용자 이름”공백으로 인해 작은 따옴표와 큰 따옴표의 조합에 주목하십시오.
나에게 "winpty"는 vscode에서 파이썬 경로를 확인할 수 없습니다.
이 답변을 살펴보십시오.
Git Bash의 경로는 다음과 같이 설정해야합니다.
PATH=$PATH:/c/Python27/
참고 URL : https://stackoverflow.com/questions/32597209/python-not-working-in-the-command-line-of-git-bash
'IT' 카테고리의 다른 글
SSMS 2008의“상위 200 개 행 편집”에서 SQL을 변경하는 방법 (0) | 2020.05.19 |
---|---|
스위프트 : switch 문의 테스트 클래스 유형 (0) | 2020.05.19 |
빈 줄없이 긴 줄을 어떻게 감쌀 수 있습니까? (0) | 2020.05.19 |
외래 키 제약 조건 : ON UPDATE 및 ON DELETE 사용시기 (0) | 2020.05.19 |
C #에서 null 검사를 수행하는 더 깨끗한 방법? (0) | 2020.05.19 |