Wie update-alternativen zu Python 3, ohne zu brechen apt?
Den anderen Tag habe ich beschlossen, dass ich wollte, dass der Befehl python standardmäßig feuern Python ist3 statt python2.
Also ich habe das:
sudo update-alternatives --install /usr/bin/python python /usr/bin /python2.7 2
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 3
sudo update-alternatives --config python -
$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 3 auto mode
1 /usr/bin/python2.7 2 manual mode
2 /usr/bin/python3.5 3 manual mode
Press <enter> to keep the current choice[*], or type selection number: 0
Ist und dass alles funktioniert. Super!!! 🙂
$ python -V
Python 3.5.2
Aber es dauerte nicht lange, bis ich merkte, ich hatte gebrochen apt/aptitude, wenn es um die Installation und das entfernen von python-apt-Pakete, da erwartet wurde python2 geschah es.
Dies ist, was passiert ist.
$ sudo apt remove python-samba
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
samba-libs
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
python-samba
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
After this operation, 5,790 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 187285 files and directories currently installed.)
Removing python-samba (2:4.3.11+dfsg-0ubuntu0.16.04.5) ...
File "/usr/bin/pyclean", line 63
except (IOError, OSError), e:
^
SyntaxError: invalid syntax
dpkg: error processing package python-samba (--remove):
subprocess installed pre-removal script returned error exit status 1
Traceback (most recent call last):
File "/usr/bin/pycompile", line 35, in <module>
from debpython.version import SUPPORTED, debsorted, vrepr, \
File "/usr/share/python/debpython/version.py", line 24, in <module>
from ConfigParser import SafeConfigParser
ImportError: No module named 'ConfigParser'
dpkg: error while cleaning up:
subprocess installed post-installation script returned error exit status 1
Errors were encountered while processing:
python-samba
E: Sub-process /usr/bin/dpkg returned an error code (1)
Schließlich dachte ich, er wollte python2 als Standard, so dass ich öffnete meine änderungen wie folgt:
$ sudo update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.5 3 auto mode
1 /usr/bin/python2.7 2 manual mode
2 /usr/bin/python3.5 3 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
$ python -V
Python 2.7.12
Und dann apt funktionierte wieder
$ sudo apt remove python-samba
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following package was automatically installed and is no longer required:
samba-libs
Use 'sudo apt autoremove' to remove it.
The following packages will be REMOVED:
python-samba
0 upgraded, 0 newly installed, 1 to remove and 0 not upgraded.
1 not fully installed or removed.
After this operation, 5,790 kB disk space will be freed.
Do you want to continue? [Y/n]
(Reading database ... 187285 files and directories currently installed.)
Removing python-samba (2:4.3.11+dfsg-0ubuntu0.16.04.5) ...
So, ich hatte zu lassen, wie es standardmäßig auf python 2, aber ich entwickeln in python 3 und so möchte mein system auf Standard-python-3, wenn ich ausführen, python und idle.
Kann mir jemand sagen, wie ich diese erreichen können, ohne zu brechen apt?
Mein system ist ein Raspberry Pi 3B unter Ubuntu:
Linux mymachine 4.4.38-v7+ #938 SMP Thu Dec 15 15:22:21 GMT 2016 armv7l armv7l armv7l GNU/Linux
(Es ist tatsächlich eine arm v8)
$ cat /etc/lsb-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=16.04
DISTRIB_CODENAME=xenial
DISTRIB_DESCRIPTION="Ubuntu 16.04.2 LTS"
- lassen Sie
python
Hinweis auf python2 oder sind Sie für viele Probleme - Ja, danke, ich dachte so viel. 🙂
Du musst angemeldet sein, um einen Kommentar abzugeben.
Pro Debian-Richtlinien,
python
bezieht sich auf Python 2 undpython3
bezieht sich auf Python 3. Versuchen Sie nicht, dies zu ändern, das ganze system oder sind Sie für die Art von ärger, die Sie bereits entdeckt.Virtuelle Umgebungen ermöglichen es Ihnen, eine isolierte Python-installation mit welcher version von Python und was-Bibliotheken, die Sie benötigen, ohne Unordnung mit dem system-Python installieren.
Mit aktuellen Python 3,
venv
ist Teil der standard-Bibliothek; mit älteren Versionen, müssen Sie möglicherweise installieren Siepython3-venv
oder ein ähnliches Paket.Eine gängige Praxis ist, eine eigene Umgebung für jedes Projekt, das Sie arbeiten, sowieso; aber wenn Sie wollen, dass dies so Aussehen, wie es effektiv systemweit und für Ihr eigenes login, könnte man hinzufügen, die Aktivierung Strophe zu Ihrem
.profile
oder ähnliches.ersetzen
mit
z.B. die Installation in
/usr/local/bin
statt/usr/bin
.sorgen und die
/usr/local/bin
ist vor/usr/bin
im WEG.d.h.
Sicherzustellen, dass dieses immer der Fall ist, durch hinzufügen
dem Ende Ihrer
~/.bashrc
- Datei. Indem derPATH
Umgebungsvariable mit benutzerdefinierten bin-Ordner wie/usr/local/bin
oder/opt/<some install>/bin
ist in der Regel empfohlen, um sicherzustellen, dass die Anpassungen gefunden werden, bevor das Standard-system ersetzt.update-alternatives
ist falsch, man darf wirklich nicht zu ersetzenpython
version 2 mitpython3
überhaupt. Die Frage beschreibt einige der gut dokumentierten, Symptomen.python
ausführbare Datei. Meine Vermutung ist, dass system-Prozesse nicht nur betrachten, $PATH, da es user-abhängig. Und das einzige, wasupdate-alternatives
tut, ist erstellen Sie einen symbolischen Link auf/usr/local/bin/python
. Gar nichts ändert sich in/usr/bin
. Solangeapt
(oder ähnlich) ist auf der Suche nach/usr/bin/python
und nicht nurpython
, sollte es in Ordnung sein. Ich getestet habe dies mit apt und es scheint in Ordnung. Dies ist keine Garantie, dass es funktioniert mit allen system-software aber!/usr/local/bin/python
zu/etc/alternatives/python
aber die zweite ist bereits auf dem system Python und der änderung seiner link-Ziel, ändert sich auch die system-Python. (Nicht in einem Ort, wo kann ich dies überprüfen, though.) Ubuntuupdate-alternatives
ist ein Nachbau, damit es funktioniert möglicherweise nicht die gleiche wie Debian ist. In jedem Fall sehe ich nicht ein, warum Sie möchten, verwenden Sie die system-weitealternatives
system zu verwalten, einen symlink in/usr/local/bin
sowieso; erstellen Sie einfach den symlink manuell.Irgendwie python 3 zurück kam (nach einigen updates?) und verursacht große Probleme mit apt-updates, also habe ich beschlossen zu entfernen python 3 vollständig von der alternativen:
python3
ist nicht eine gültige alternative fürpython
weil es muss beziehen sich auf Python 2.Da ich nicht wollen, etwas zu brechen, habe ich diese nutzen zu können neuere Versionen von Python ist3 als Python v3.4 :