Ändern Sie die Standard-Python-Version unter Raspbian GNU/Linux
Um auf Ihrem Raspbian GNU/Linux zur Standard-Python-Version zu wechseln, listen Sie zunächst alle verfügbaren Python-Versionen auf:
ls /usr/bin/python*
/usr/bin/python /usr/bin/python2 /usr/bin/python2.7 /usr/bin/python3 /usr/bin/python3.2 /usr/bin/python3.2mu /usr/bin/python3mu
Ihre Ausgabe kann anders sein. Wenn die Version, nach der Sie suchen, nicht verfügbar ist, verwenden Sie den Befehl apt-get, um sie zu installieren. Zb. apt-get install python3
Nächste Setup-Alternativen:
update-alternatives --install /usr/bin/python python /usr/bin/python2.7 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in auto mode
update-alternatives --install /usr/bin/python python /usr/bin/python3.2 2
update-alternatives: using /usr/bin/python3.2 to provide /usr/bin/python (python) in auto mode
Da wir python3.2 mit einer höheren Priorität eingerichtet haben, sollte es jetzt Ihre Standardeinstellung sein:
python --version
Python 3.2.3
Um zwischen den Python-Versionen zu wechseln, verwenden Sie den Befehl update-alternatives:
update-alternatives --config python
There are 2 choices for the alternative python (providing /usr/bin/python).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/bin/python3.2 2 auto mode
1 /usr/bin/python2.7 1 manual mode
2 /usr/bin/python3.2 2 manual mode
Press enter to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/bin/python2.7 to provide /usr/bin/python (python) in manual mode
Ihre Python-Version sollte nun geändert werden, um die obige Auswahl widerzuspiegeln:
python --version
Python 2.7.3