Im aktuellen Raspbian OS (Stand 16.08.2020), basierend auf Debian 10 Buster, ist noch Python in der Version 2.7.16 als Standard eingestellt. Da die Python Version 2 seit dem 01.01.2020 keine Updates, Bugfixes und Support erhält sollten alle Programme auf Python 3 portiert werden und Python 3 ebenfalls als Standard unter Raspbian OS verwendet werden. Python 3 ist im aktuellen Release schon vorinstalliert, es braucht nur noch zum Standard gesetzt zu werden.
Die aktuell installierten Python Versionen kann man sich wie folgt anzeigen lassen.
pi@raspberrypi:~ $ python --version Python 2.7.16 pi@raspberrypi:~ $ python3 --version Python 3.7.3 |
Standardprogramme können unter Debian basierten Distributionen mit dem Programm "update-alternatives" gesetzt werden. Dadurch werden entsprechende symbolische Links auf das jeweilige Programm gesetzt und kann sofort verwendet werden. Python ist allerdings für "update-alternatives" noch nicht registriert, bzw. installiert.
pi@raspberrypi:~ $ sudo update-alternatives --list python update-alternatives: error: no alternatives for python |
Um nun die beiden Python Versionen hinzuzufügen kann "update-alternatives" wieder verwendet werden.
pi@raspberrypi:~ $ sudo 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 pi@raspberrypi:~ $ sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.7 2 update-alternatives: using /usr/bin/python3.7 to provide /usr/bin/python (python) in auto mode |
Die Syntax für die Installation lautet update-alternatives --install <Link> <Name> <Pfad> <Priorität>. Es reicht dabei die Major Versionen von Python anzugeben, in dem Fall 2.7 anstatt 2.7.16 und 3.7 anstatt 3.7.3. Die höhere Priorität (1 bei Version 2.7 und 2 bei Version 3.7) wird dabei als Standard gesetzt. Die Änderungen sind sofort wirksam wie ein Aufruf von "python" zeigt.
pi@raspberrypi:~ $ python --version Python 3.7.3 |
Ebenfalls werden nun die registrierten Versionen von Python angezeigt.
pi@raspberrypi:~ $ update-alternatives --list python /usr/bin/python2.7 /usr/bin/python3.7 |
Um später die Standardversion wieder zu ändern kann ebenfalls update-alternatives verwendet werden.
pi@raspberrypi:~ $ 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.7 2 auto mode 1 /usr/bin/python2.7 1 manual mode 2 /usr/bin/python3.7 2 manual mode Press <enter> to keep the current choice[*], or type selection number: pi@raspberrypi:~ $ |
Die mit Stern markierte Version ist in diesem Fall die Standardversion. Ältere Versionen können über update-alternatives auch wieder entfernt werden.
pi@raspberry:~ $ sudo update-alternatives --remove python /usr/bin/python3.7 |
Sie planen ein IoT, Automatisierungs- oder Embedded Projekt? Mit über 30 Jahren Erfahrung und zertifiziert nach DIN EN ISO 9001:2015 unterstützen wir Sie in jeder Phase Ihres Projektes. Ob Auswahl der geeigneten Hardware, Planung, Projektierung und Umsetzung, individuelle Anpassungen, Implementierung, Logistik oder Ausbau und Betreuung der Infrastruktur - sprechen Sie uns einfach an. Zu fairen Konditionen setzen wir gemeinsam mit Ihnen das Projekt erfolgreich um. Kontakt: IoT@ico.de oder telefonisch unter 06432 / 9139 - 320 |