Il se peut en effet qu'il soit nécessaire de "jouer" avec les versions de python afin de lancer des programmes en python version 2 ou 3 ou bien de sélectionner une version version précise de python 3 (3.10 ou 3.11 par exemple) .
Ce tutoriel explique cela pour python, mais ce sera le même schéma avec n'importe quel autre logiciel (firefox, etc.)
Tester la version de python en cours
Code : Tout sélectionner
python --version
Python 3.10.6
Lister les versions disponibles sur le système
Code : Tout sélectionner
ls -l /usr/bin/python*
lrwxrwxrwx 1 root root 24 févr. 17 12:20 /usr/bin/python -> /etc/alternatives/python
-rwxr-xr-x 1 root root 3592504 juil. 1 2022 /usr/bin/python2.7
lrwxrwxrwx 1 root root 10 déc. 31 12:35 /usr/bin/python3 -> python3.10
-rwxr-xr-x 1 root root 5921160 nov. 14 17:10 /usr/bin/python3.10
-rwxr-xr-x 1 root root 6890080 août 12 2022 /usr/bin/python3.11
-rwxr-xr-x 1 root root 960 janv. 25 09:29 /usr/bin/python3-futurize
-rwxr-xr-x 1 root root 964 janv. 25 09:29 /usr/bin/python3-pasteurize
Comment basculer sur un appel par défaut de python 2 plutôt que de python 3 ?
On utilise update-alternatives afin de sélectionner quelle version utiliser.
Lister les versions enregistrées par update-alternatives
Code : Tout sélectionner
sudo update-alternatives --list python
update-alternatives: error: no alternatives for python
Ajouter une version de python
On inscrit la version de python 2.7
Code : Tout sélectionner
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
Code : Tout sélectionner
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.10 2
La version 3.11
Code : Tout sélectionner
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.11 3
Code : Tout sélectionner
sudo update-alternatives --list python
/usr/bin/python2.7
/usr/bin/python3.10
/usr/bin/python3.11
Sélectionner la version adéquate
Code : Tout sélectionner
sudo update-alternatives --config python
Il existe 3 choix pour l'alternative python (qui fournit /usr/bin/python).
Sélection Chemin Priorité État
------------------------------------------------------------
0 /usr/bin/python3.11 3 mode automatique
1 /usr/bin/python2.7 1 mode manuel
* 2 /usr/bin/python3.10 2 mode manuel
3 /usr/bin/python3.11 3 mode manuel
Appuyez sur <Entrée> pour conserver la valeur par défaut[*] ou choisissez le numéro sélectionné :
Vérification
Code : Tout sélectionner
python --version
Python 2.7.18
Code : Tout sélectionner
update-alternatives --query python
Name: python
Link: /usr/bin/python
Status: manual
Best: /usr/bin/python3.11
Value: /usr/bin/python2.7
Alternative: /usr/bin/python2.7
Priority: 1
Alternative: /usr/bin/python3.10
Priority: 2
Alternative: /usr/bin/python3.11
Priority: 3
Et l'option "auto" ? si l'entrée est configurée sur l'option "auto" ce sera la dernière version de python qui sera appelée.
Code : Tout sélectionner
sudo update-alternatives --auto python
Code : Tout sélectionner
sudo update-alternatives --remove python /usr/bin/python3.11
Code : Tout sélectionner
sudo update-alternatives --remove-all python