Python readline Bug
Problem
In the Python interpreter whenever I hit enter it would show a blank line without a prompt and I'd have to press enter again to see the prompt. When I exited the interpreter the terminal would not show anything I typed. Pressing the return key would show my shell prompt on the same line. Up arrow or down arrow keys did not make any difference. reset was a last resort.
For example,
Python 3.4.3 (default, Aug 26 2015, 18:29:14) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> abs(1-0) >>> 1 >>> ^D>>> ~ $ ~ $ ~ $ reset
Investigation
I uninstalled all packages in MacPorts and then only installed Python 3.4.
~ $ sudo port install python34 ~ $ port installed The following ports are currently installed: bzip2 @1.0.6_0 (active) expat @2.1.0_0 (active) gettext @0.19.6_0 (active) libedit @20150325-3.1_0 (active) libiconv @1.14_0 (active) ncurses @6.0_0 (active) openssl @1.0.2d_0 (active) python3_select @0.0_1 (active) python34 @3.4.3_5 (active) python_select @0.3_5 (active) sqlite3 @3.8.11.1_0 (active) xz @5.2.1_0 (active) zlib @1.2.8_0 (active)
My repro steps for the symptoms.
~ $ which -a python3.4 /opt/local/bin/python3.4 ~ $ python3.4 Python 3.4.3 (default, Aug 26 2015, 18:29:14) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> abs(1-0) >>> 1 >>> ^D>>> ~ $ ~ $ ~ $ reset ~ $
Solution
A lot of DuckDuckGo searching pointed at a possible cause: use of libedit instead of readline on OS X. A possible solution was found at libedit/readline conflict with ipython 3.2.2 on OS X 10.7 Lion.
I installed readline from MacPorts.
~ $ sudo port install py34-readline
These were the packages installed.
~ $ port installed The following ports are currently installed: bzip2 @1.0.6_0 (active) expat @2.1.0_0 (active) gettext @0.19.6_0 (active) libedit @20150325-3.1_0 (active) libiconv @1.14_0 (active) ncurses @6.0_0 (active) openssl @1.0.2d_0 (active) py34-readline @6.2.4.1_1 (active) py34-setuptools @18.2_0 (active) python3_select @0.0_1 (active) python34 @3.4.3_5 (active) python_select @0.3_5 (active) sqlite3 @3.8.11.1_0 (active) xz @5.2.1_0 (active) zlib @1.2.8_0 (active)
My repro steps showed the symptom was gone.
~ $ which -a python3.4 /opt/local/bin/python3.4 ~ $ python3.4 Python 3.4.3 (default, Aug 26 2015, 18:29:14) [GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.56)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> abs(1-0) 1 >>> >>> ~ $ ~ $
Conclusion
Folks, install readline when installing Python on Mac OS X.