2016-11-04 7 views
4

Ich habe sowohl Python 2.7 und 3.5 installiert. Wenn ich ein Skript von der Kommandozeile mit python ausführen, verwendet es Python 2.7, aber wenn ich ipython starten, verwendet es Python 3:Wie iPython verwendet Python 2 anstelle von Python 3

[email protected]:~$ python -V 
Python 2.7.12 
[email protected]:~$ ipython 
Python 3.5.2 (default, Sep 10 2016, 08:21:44) 
Type "copyright", "credits" or "license" for more information. 

IPython 5.1.0 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 

In [1]: 

Gibt es eine Möglichkeit ipython zu starten, so dass es 2 Python verwendet? (Ich benutze Ubuntu LTS 16.04).

+0

Wie haben Sie ipython installiert? – Nurjan

+0

Ich bin immer noch auf der Suche nach einer Lösung, weil die virtuellen Umgebungen keinen Zugriff auf andere Module haben, die nicht mit 'pip' installiert wurden, wie' rethinkdb'. [Nurzhan] (http://stackoverflow.com/users/671150/nurzhan), ich erinnere mich nicht genau, wie ich iPython installiert habe, aber ich glaube, ich habe die .whl-Datei heruntergeladen und 'pip install [ipython_file] .whl' . –

+0

Ich installierte ipython auf xubuntu 16.04 LTS mit 'sudo apt-get install ipython'. Es verwendet standardmäßig Python 2.7.12. Ich weiß nicht, warum du dieses Problem hast. Ich weiß, dass vim ab Ubuntu 16.04 LTS standardmäßig mit python3 läuft. – Nurjan

Antwort

1

Folge ipython reads wrong python version, in /usr/local/bin/ipython, habe ich einfach

geändert
#!/usr/bin/python3 

in der ersten Zeile zu

#!/usr/bin/python 

und Python 2 ist die Standardversion von ipython verwendet werden:

[email protected]:~$ ipython 
Python 2.7.12 (default, Jul 1 2016, 15:12:24) 
Type "copyright", "credits" or "license" for more information. 

IPython 2.4.1 -- An enhanced Interactive Python. 
?   -> Introduction and overview of IPython's features. 
%quickref -> Quick reference. 
help  -> Python's own help system. 
object? -> Details about 'object', use 'object??' for extra details. 
2

Weniger aufdringliche Lösung (wie meine Lösung unten braucht nicht ändern g alle Bibliotheksdateien für dieses Problem) ist

python2.7 -m IPython notebook 

so der allgemeine Befehl ist

{{Python-you-want-ipython-to-use}} -m IPython Notebook

Warum das wird funktionieren ?

Denn wenn Sie sehen die ipython script (/ usr/local/bin/ipython) scheint es selbst ein Python-Skript zu sein, und es hat die shebang (#!/Usr/bin/python3), so dass die ipython ist keine eigenständige binäre, aber es wird Leben wegen einiger Python. Da das ipython-Skript selbst etwas Python benötigt, um es auszuführen, führen Sie das ipython-Modul direkt mit einem Python Ihrer Wahl aus, anstatt das/usr/local/bin/ipython für Sie zu entscheiden, und das ist der Fix für das Problem von 'was Python ipython verwendet'.

0

jetzt unterstützt IPython 6.0+ nicht Python 2.6, 2.7, 3.0, 3.1 oder 3.2. Wenn Sie Python 2.7 verwenden, installieren Sie bitte IPython 5.x LTS Long Term Support Version.

Ab IPython 6.0 ist Python 3.3 und höher erforderlich.

Verwandte Themen