Recherche de site Web

Changer la version par défaut de python sur Raspbian GNU/Linux


Afin de passer à la version python par défaut sur votre Raspbian GNU/Linux, listez d’abord toutes les versions de python disponibles :


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

Votre production peut être différente. Si la version que vous recherchez n’est pas disponible, utilisez la commande apt-get pour l’installer. Eg. apt-get install python3
Alternatives d’installation suivantes :


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

Puisque nous avons configuré python3.2 avec une priorité plus élevée, il devrait maintenant être votre valeur par défaut :


python --version
Python 3.2.3

Pour basculer entre les versions de python, utilisez la commande 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

Votre version de python doit maintenant être modifiée pour refléter la sélection ci-dessus :


python --version
Python 2.7.3

Articles connexes: