Die Verwendung von Python vermasselt die Shell (und/oder das Terminal?)!

Das Problem

Durch einfaches Öffnen und Schließen der Python-Sub-Shell wird meine Shell (oder möglicherweise das Terminal?) vermasselt. Es scheint die Fähigkeit der Shell zu entfernen, jeden von mir eingegebenen Text zu drucken, einschließlich Zeilenumbrüchen, nachdem ich einen Befehl eingegeben habe.

Das Problem tritt bei python3.4, python2.7 und python2.6 auf, aber nicht bei python2.5.

Es ist noch nie zuvor aufgetreten (das ist mir aufgefallen), und es passiert nicht bei anderen Softwarepaketen, die ich verwendet habe (VIM, Emacs usw.).

Ich habe bestätigt, dass es mit Apples Standard-Terminal (Version 2.2.3 [303.2]), iTerm2 (Build 2.1.1) und XTerm (269) kaputt geht.

Interessanterweise bricht es unter bash, aber nicht unter zshoder csh.

Beispielhaftes Verhalten

Um zu demonstrieren, mache ich Folgendes ( $SHELList /bin/bash):

  1. Laufen which python3.4.
  2. Laufen python3.4.
  3. Drücken Sie einmal die Eingabetaste und geben Sie dann exit()die Python-Shell ein.
  4. Drücken Sie noch zweimal die Eingabetaste.
  5. Geben Sie ein python3.4 --version.

Hier ist, was ich für einige der primären Versionen von Python sehe, die ich installiert habe:

Python3.4 – problematisch

myself@localhost:~$ which python3.4
python3.4 is /opt/local/bin/python3.4
python3.4 is /opt/local/bin/python3.4
myself@localhost:~$ python3.4
Python 3.4.3 (default, Aug 24 2015, 17:25:38)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.12)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> exit()
>>> myself@localhost:~$ myself@localhost:~$ myself@localhost:~$ Python 3.4.3
myself@localhost:~$

Python2.7 – problematisch

myself@localhost:~$ which python2.7
python2.7 is /opt/local/bin/python2.7
python2.7 is /usr/local/bin/python2.7
python2.7 is /usr/bin/python2.7
python2.7 is /Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
python2.7 is /usr/bin/python2.7
python2.7 is /usr/local/bin/python2.7
python2.7 is /opt/local/bin/python2.7
myself@localhost:~$ python2.7
Python 2.7.10 (default, Aug 24 2015, 11:54:49)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> exit()
>>> myself@localhost:~$ myself@localhost:~$ myself@localhost:~$ Python 2.7.10
myself@localhost:~$

Python2.6 – problematisch

myself@localhost:~$ which python2.6
python2.6 is /opt/local/bin/python2.6
python2.6 is /usr/bin/python2.6
python2.6 is /usr/bin/python2.6
python2.6 is /opt/local/bin/python2.6
myself@localhost:~$ python2.6
Python 2.6.9 (unknown, Aug 24 2015, 17:53:21)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.1.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> exit()
>>> myself@localhost:~$ myself@localhost:~$ myself@localhost:~$ Python 2.6.9
myself@localhost:~$

Python2.5 -- Es funktioniert!

myself@localhost:~$ which python2.5
python2.5 is /usr/bin/python2.5
python2.5 is /usr/bin/python2.5
myself@localhost:~$ python2.5
Python 2.5.6 (r256:88840, Jul 31 2011, 19:30:45)
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> exit()
myself@localhost:~$
myself@localhost:~$
myself@localhost:~$ python2.5 --version
Python 2.5.6
myself@localhost:~$

Läuft es ein zshoder cshscheint gut zu funktionieren:

Zsch

myself@localhost:~$ zsh
localhost% which python3.4
/opt/local/bin/python3.4
localhost%
localhost% python3.4
Python 3.4.3 (default, Aug 24 2015, 17:25:38)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.12)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> exit()
>>> %                                                                           
ra%
ra%
ra% python3.4 --version
Python 3.4.3
localhost% exit
myself@localhost:~$

Tsch

myself@localhost:~$ csh
Running csh
[localhost:~] myself% which python3.4
/opt/local/bin/python3.4
[localhost:~] myself% python3.4
Python 3.4.3 (default, Aug 24 2015, 17:25:38)
[GCC 4.2.1 Compatible Apple Clang 3.0 (tags/Apple/clang-211.12)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> exit()
>>> [localhost:~] myself%
[localhost:~] myself%
[localhost:~] myself% python3.4 --version
Python 3.4.3
[localhost:~] myself% exit
exit

Meine Überlegung bisher:

Die Tatsache, dass das Verhalten für drei Terminals gleich zu sein scheint, lässt mich glauben, dass es sich nicht um ein Terminalproblem handelt.

Die Tatsache, dass es in Zsh und Csh funktioniert, aber nicht in Bash, lässt mich denken, dass es ein Shell-Problem ist.

Die Tatsache, dass die kaputten Versionen (3.4, 2.7, 2.6) alle unter /opt/local/bin/(dem üblichen Installationsort von MacPorts) installiert sind, aber die Version, die funktioniert (2.5), unter installiert ist /usr/bin/, lässt mich fragen, ob ein aktuelles MacPorts-Update (vielleicht bis zu 20 Tage vor dem 24. August 2015??) ist möglicherweise etwas kaputt gegangen, wodurch Python und Bash nicht zusammenarbeiten können!

Eine Vermutung - die Macports-Pythons sind nicht mit GNU readline verbunden - versuchen Sie, pyXX-readline zu installieren
Neben der @Mark-Lösung und bis das Problem behoben ist, beenden Sie Python mit exit() , quit(), oder geben Sie an der Eingabeaufforderung control Dein reset(es wird nicht an das Terminal zurückgesendet) und warten Sie, bis die Eingabeaufforderung erneut angezeigt wird.
@Markus: Das hat funktioniert! Wenn Sie es als Antwort schreiben, werde ich es akzeptieren. Vielen Dank!

Antworten (1)

Es scheint ein Problem mit neueren Macports-Builds von Python zu geben, siehe diesen Fehler

Eine Problemumgehung besteht darin, pyXX-readline zu installieren (py35-readline wurde nur für diesen Fehler erstellt).

Eine andere Möglichkeit besteht darin, Python zu installieren und die Variante +readline hinzuzufügen