Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terminal display of input goes out of sync while/after using python? (temporary fix = `reset`)

Every time that I run python or python3 with an interactive console, the display of the prompt gets out of sync almost immediately after the first or second interaction:

>>> [1,2,3]
>>> [1, 2, 3]
print('hi')
>>> hi

Then, when I exit out of python, this behavior carries over to bash, with the addition that when you type, nothing appears on the screen, but it will still run. In the following example, I typed date and then history | tail -n3:

$ Thu Oct  8 07:55:47 CEST 2015
$   488  python
  489  date
  490  history | tail -n3

However, after typing reset, everything goes back to normal.

Needless to say, this behavior is very annoying. What is the cause, and how can I fix it?

I am on OS X. Using iTerm or built-in Terminal.app both give the same behavior. My python builds are from macports. This problem is not present with /usr/bin/python (python 2.7.2, included with OS X).

============================

Edit: If I use zsh, then python still has problems, but everything works fine in zsh after I exit out of python.

$TERM is xterm-256color in both bash and zsh.

like image 884
reynoldsnlp Avatar asked Oct 08 '15 06:10

reynoldsnlp


2 Answers

@Mark has the explanation.

As for the fix:

port selfupdate
# port install python(26|27|34|35) +readline
port install python27 +readline
like image 108
dnozay Avatar answered Sep 29 '22 11:09

dnozay


Try the stty sane command in shell.

like image 26
mrvol Avatar answered Sep 29 '22 12:09

mrvol