2

I will try to be as descriptive but brief as possible...

I have been using GitBash in that past on Win10 successfully. I came back to my Windows machine after not using it for a bit and can't seem to get it to launch python scripts it ran without issue previously. I have an alias created for Python3 called py. For instance...

$ py --version
Python 3.7.1

I can get into the iterator just fine

$ py -i
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>

I can run my scripts just fine in the iterator. Exiting with ctrl+z throws an error, however. In conjunction with this error, when I try to run the scipts from the command line, it hangs and does not respond. See below...

$ py -i
Python 3.7.1 (v3.7.1:260ec2c36a, Oct 20 2018, 14:57:15) [MSC v.1915 64 bit 
(AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>       0 [sig] bash 5224! sigpacket::process: Suppressing signal 18 to 
win32 process (pid 5160)

>>> exit()

$ py Lottery.py

It does nothing from this point, until I hit "Enter", at which time it throws a python error and returns me to my command line. I know the python script to be working. I can post the python error if it is helpful, though I think it is a red-herring and not art of the GitBash issue at hand.

Any ideas as to why GitBash is not playing well while trying run python scripts? Thanks in advance!

1
  • In bash Ctrl-Z stops the current process (you can then use bg to make it continue in the background or fg to give it back the terminal focus). If you want to stop Python try Ctrl-D.
    – xenoid
    Feb 8, 2019 at 0:14

1 Answer 1

6

This is a known issue for windows 10. GitBash's terminal has issues with windows-native apps, such as python, powershell, ipython, etc.

  • The terminal eats events, such as your screenshot. This breaks ctr+c / ctrl+z events, preventing exiting
  • In addition, those apps break cursor movement, massively corrupted the shell.

The solution is to run winpty, which you should already have from git-bash. Now git-bash is able to run apps without issues.

$ winpty python -i

This fixes both python -i, ipython -i, powershell. I use the following aliases:

alias ipython='winpty ipython'
alias python='winpty python'
alias node='winpty node'
alias powershell='winpty powershell'

An alternate solution is to use a different terminal, such as Windows Terminal

Recently windows released a new Windows Terminal

Now it supports all bash apps, full utf-8 support (the best of any Windows terminals I've ever seen, 256+ ANSI colors, etc.) You no longer need winpty.

Edit your JSON config to use:

"commandline" : "ipython.exe"

If you are using python -i at all, check out ipython.

Combine that with winpty or the terminal to run ipython. It's a huge upgrade to quality of life and usability.

It adds a lot.

  • get function signatures and docs using foo? and foo??
  • copy->paste works.
  • quality of life using any statements longer than one line are hugely improved
  • syntax highlighting, even matches braces
  • tab completion of names and inspection of attributes such as:
x = "hi world"
x.<tab> # all `str` methods pop-up.

# or
import time
time.monotonic?

Get it using

python -m pip install ipython

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.