Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Arrow keys no longer work in Python shell after upgrading Mac OS to Sierra

I'm using zsh, iTerm2 (3.0.9), and pyenv (1.0.2) with pyenv global set to 3.5.2.

In the Python shell, the up and down arrow keys used to work, to access the previous commands in the history. But now after upgrading to OSX 10.12, instead it shows control characters. For example up arrow displays:

^[[A

I've tried installing readline as suggested in Seeing escape characters when pressing the arrow keys in python shell but that didn't help. I don't have the PYTHONSTARTUP variable but didn't used to before, and not sure how that interacts with pyenv.

like image 810
danib Avatar asked Oct 01 '16 14:10

danib


4 Answers

I solved it by installing python from homebrew:

brew unlink python
brew install python
like image 128
jsphpl Avatar answered Nov 16 '22 19:11

jsphpl


I had the exact same issue and this command worked for me easy_install -a readline.

Full credit here: ipython complaining about readline

like image 30
joanfihu Avatar answered Nov 16 '22 19:11

joanfihu


This worked for me:

CFLAGS="-I$(brew --prefix readline)/include -I$(brew --prefix openssl)/include -I$(xcrun --show-sdk-path)/usr/include" \
LDFLAGS="-L$(brew --prefix readline)/lib -L$(brew --prefix openssl)/lib" \
PYTHON_CONFIGURE_OPTS=--enable-unicode=ucs2 \
pyenv install -v 2.7.11

Source: https://medium.com/@pimterry/setting-up-pyenv-on-os-x-with-homebrew-56c7541fd331#.urbdkrc9l

like image 3
Joe Inner Avatar answered Nov 16 '22 19:11

Joe Inner


This can happen with upgrading XCode or XCode tools (which often occurs with an OS upgrade) when using brew installed python.

In this case, you just need to reinstall:

brew reinstall python

If you need python 2, remember brew defaults to python3 now, so you need:

brew reinstall python2
like image 2
Zim Avatar answered Nov 16 '22 17:11

Zim