Python doesn't work on git bash command line

Python will not run on git bash (Windows). When I write python on the command line, it takes me to an empty line, not to mention that it introduced python 2.7.10, as it does in Powershell. This does not give me an error message, but python just does not start.

I have already made sure that the environment variables in PATH are included c:\python27 . What else can I check?




The session in which this problem occurs is as follows:

 user@hostname MINGW64 ~ $ type python python is /c/Python27/python user@hostname MINGW64 ~ $ python 

... sits there, not returning to the invitation.

+153
git python command-line windows git-bash
Sep 15 '15 at 23:18
source share
15 answers

Just enter this into the git shell in windows -> alias python='winpty python.exe' , that is all, and you will have an alias for the python executable. Enjoy

PS For a permanent alias, see below.

 cd ~ touch .bashrc 

then open .bashrc, add your command on top and save the file. You need to create a file through the console or you cannot save it with the corresponding name. You also need to restart the shell to apply the change.

+243
Apr 10 '16 at 2:05
source share

I do not see the following option in the answer list, but I can get an interactive prompt with the -i switch:

 $ 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. >>> 
+56
Sep 29 '16 at 19:44
source share

This is a known bug in MSys2 that provides the terminal used by Git Bash. You can get around this by running the Python build without ncurses support or using WinPTY , used as follows:

To run the Windows console program in mintty or Cygwin sshd, add console.exe to the command line:

 $ 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() 

ready-made binaries for msys will most likely work with Git Bash. (Check if there is a newer version if a considerable time has passed since the publication of this answer!).




As with Git for Windows 2.7.1, try using winpty c:Python27/python.exe ; WinPTY can be included out of the box.

+52
Sep 16 '15 at 3:38
source share

I am a Windows 10 user and I installed GIT on my system, just accepting the default values.

After reading the answers above, I got 2 own solutions, and these 2 solutions work great on GIT bash and help me execute Python expressions on GIT bash.

I am attaching 3 images of my GIT bash terminal. 1st with a problem, and 2nd as a solution.

PROBLEM - The cursor just waits after pressing the python command

enter image description here

SOLUTION 1

Run winpty <path-to-python-installation-dir>/python.exe on the winpty <path-to-python-installation-dir>/python.exe bash terminal.

Note: do not use C:\Users\Admin as the path style in GIT bash, use /C/Users/Admin instead.

In my case, I executed winpty/C/Users/SJV/Anaconda2/python.exe on GIT bash

Or, if you do not know your username, run winpty/C/Users/$USERNAME/Anaconda2/python.exe

enter image description here

SOLUTION 2

Just enter python -i and that’s it.

enter image description here

Thank you

+33
Mar 20 '18 at 12:49
source share

In addition to @ Charles-Duffy's answer, you can use winpty directly without installing / downloading anything extra. Just run winpty c:/Python27/python.exe . The winpty.exe utility can be found in Git \ usr \ bin. I am using Git for Windows v2.7.1

The pre-created binaries from @ Charles-Duffy are version 0.1.1 (according to the file name), and the included one is 0.2.2

+7
Feb 08 '16 at 22:26
source share

In addition to @Vitaliy Terziev's answer

try touch.bash_profile and then add an alias to the file.

+1
Jan 11 '18 at 6:46
source share

You can change the target for the Git Bash shortcut from:

 "C:\Program Files\Git\git-bash.exe" --cd-to-home 

at

 "C:\Program Files\Git\git-cmd.exe" --no-cd --command=usr/bin/bash.exe -l -i 

This is how ConEmu used to run git bash (version 16). The latest version launches this normally, and this is how I got there ...

+1
Jan 14 '18 at 6:39
source share

type "winpty python" and it will work

Gitbash has some problems when running any command that starts with python. this also applies to any python manage.py commands. Always start with 'winpty python manage.py'. At least that's what suits me. Running Windows 10.

+1
Feb 14 '18 at 19:51
source share

I am using MINGW64 through Visual Studio Code on Windows 10 and trying to install node-sass (this requires python2 ). I followed felixrieseberg / windows-build-tools # 56 on Github, which solved my problem.

This is a special case, but I write in case someone has the same problem:

npm --add-python-to-path='true' --debug install --global windows-build-tools

This installs Python and other necessary build tools in %USERPROFILE%\.windows-build-tools\python27 .

+1
Jul 24 '18 at 17:35
source share

Another example of this problem is using the AWS Elastic Beanstalk command-line interface (awsebcli, eb cli) from git bash (MINGW64, Mintty) on Windows (using git version 2.19.0.windows.1).

I'm just posting this because it took me a while to get here and search for eb-cli issues.

Commands such as eb init or eb config save , which require user input, seem to cause freezes / freezes. In fact, I think the console is not updated with text asking for user input. Moreover, eb deploy updates the console text only after the command is completed, so I do not see the progress update until it is completed.

As mentioned in the git release notes for windows (for v2.19.0) and, for example, in the Xun Yang answer , the workaround should be done

winpty eb <command> (instead of just eb <command> )

An alternative, as suggested in this git issue for Windows , could be to use a native Windows console instead of mintty (an option during git installation).

0
Sep 19 '18 at 14:08
source share

For python version 3.7.3 in vscode with gitbash as the default terminal, I did this for a while, and then followed @Vitaliy Terziev's advice on adding an alias to .bashrc, but with the following specification:

alias python = "/ c / Users / my username /AppData/Local/Programs/Python/Python37/python.exe"

Note the combination of single and double quotes because of the spaces "my username".

For me, "winpty" cannot resolve the Python path in vscode.

0
May 21 '19 at
source share

Git Bash Workaround - Run Python 2 and 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 => add aliases to the aliases file for which Git Bash uses.

The Git Bash aliases file is aliases.sh . It is in:

C:\path where you installed Git\etc\profile.d\aliases.sh

1) Open (using a text editor such as Atom or another) the aliases.sh file

for example: in my case, the file is located in C:\Software\Develop\Git\etc\profile.d\aliases.sh

2) Add your alias for Python

In my case, python.exe is installed in:

 C:\Networking\Network Automation\Python 2.7\python.exe C:\Networking\Network Automation\Python 3.7\python.exe 

So you have to create 2 aliases, one for Python 2 (I called python2 ) and the other for Python 3 (I just called python ). Git Bash uses the linux file structure, so you need to change "\" to "/", and if you have a path like in my Network Automation example you put it with ""

Network Automation, for example

winpty is a magic command that invokes an executable file.

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 change other aliases (if you want)

I also changed the alias ll to show all files in a readable list:

 alias ll='ls -lah' 



4) Save the aliases.sh file




5) OK !!! close and restart your git bash

Now you can constantly run both Python directly from the Git shell, just by writing

$ python run Python 3

$ python2 run Python 2

$ ll β†’ enter ls -lah to quickly show your detailed list of files

Hooray Harry

0
May 21 '19 at 17:07
source share

Try python -i instead of python , this is a cursor thing.

0
May 22 '19 at 20:01
source share

Take a look at this answer:

Git Bash will not run my python files?

The path in Git Bash should be set as follows:

 PATH=$PATH:/c/Python27/ 
-one
Sep 15 '15 at 23:25
source share

To run the script in the current shell, use either . Scripts/activate . Scripts/activate , or source Scripts/activate

-2
Mar 24 '16 at 15:45
source share



All Articles