Bonjour,

Je suis sur Ubuntu 18.04 x64

Avec la version de python par défault
laurent@Laurent-I7-9900K:~$ python -V
Python 2.7.17
laurent@Laurent-I7-9900K:~$


Je voudrais savoir comment je peux installer Python 2.7.6 de Ubuntu 14.04 sur Ubuntu 18.04 sans désinstaller ou endommager Python 2.7.17.

Faut-il faire ceci :
wget  https://www.python.org/ftp/python/2.7.6/Python-2.7.6.tgz
tar xf Python-2.7.6.tgz
cd Python-2.7.6
./configure
make
sudo make install

sudo update-alternatives --config python
Est-ce que python 2.7.17 et 3 ne seront pas endommager ?
J'ai besoin de python 2.7.6 pour faire fonctionner un programme sur cette version.
Je ne sais pas comment faire pour avoir plusieurs version de python sur Linux ?

Merci d'avance, pour vos avis et conseils.
salut...
personne pour te répondre hier soir alors je te propose une solution...
avec un machine aussi puissante, pourquoi ne pas te faire des VM ?
Bonjour,
Je ne comprends pas trop pourquoi tu veux python 2.7.6. La différence entre 2.7.6 et 2.7.17 doit être de l'épaisseur d'un cheveu donc je serais surpris qu'un programme tournant avec 2.7.6 ne tournerait pas avec 2.7.17.
Re,

L'appli créé en 2.7.6 ne fonctionne pas sur Python 2.7.17
laurent@Laurent-I7-9900K:~$ /home/laurent/Langages/python/2.7.6/mag_5-3.py
from: trop d'arguments
from: trop d'arguments
import-im6.q16: not authorized `os' @ error/constitute.c/WriteImage/1037.
from: trop d'arguments
import-im6.q16: not authorized `datetime' @ error/constitute.c/WriteImage/1037.
from: trop d'arguments
from: trop d'arguments
import-im6.q16: not authorized `pip' @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized `sys' @ error/constitute.c/WriteImage/1037.
import-im6.q16: not authorized `shutil' @ error/constitute.c/WriteImage/1037.
/home/laurent/Langages/python/2.7.6/mag_5-3.py: ligne 39: erreur de syntaxe près du symbole inattendu « ( »
/home/laurent/Langages/python/2.7.6/mag_5-3.py: ligne 39: `def date_et_heure():'
laurent@Laurent-I7-9900K:~$ 
Alors que sur Ubuntu 14.04 qui est donc python 2.7.6 l'appli fonctionne ???

Merci.
J'ai surtout l'impression que le programme est mal exécuté au vu du retour. Que donne ceci ?

pour vérifier ce qu'il en est
/usr/bin/python --version
/usr/bin/python2 --version
(ci-dessous affiche les dix premières lignes du programme. Si jamais il y a des choses confidentielles, remplace-les par des signes *)
head /home/laurent/Langages/python/2.7.6/mag_5-3.py

et pour essayer de lancer en forçant python2 comme interpréteur
/usr/bin/python2 /home/laurent/Langages/python/2.7.6/mag_5-3.py
re,

Voici le retour
laurent@Laurent-I7-9900K:~$ /usr/bin/python --version
Python 2.7.17
laurent@Laurent-I7-9900K:~$ 
laurent@Laurent-I7-9900K:~$ /usr/bin/python2 --version
Python 2.7.17
laurent@Laurent-I7-9900K:~$
laurent@Laurent-I7-9900K:~$ head /home/laurent/Langages/python/2.7.6/Eric-mag/mag_5-3.py

# -*- coding:utf-8 -*-

# python /home/laurent/Langages/python/2.7.6/Eric-mag/mag_5.py

#-----------------------------------------------------------------------------------------------------
#                                     RESTE A FAIRE
#-----------------------------------------------------------------------------------------------------

laurent@Laurent-I7-9900K:~$ 
laurent@Laurent-I7-9900K:~$ sudo pip install xlwt
[sudo] Mot de passe de laurent : 
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
DEPRECATION: Python 2.7 reached the end of its life on January 1st, 2020. Please upgrade your Python as Python 2.7 is no longer maintained. pip 21.0 will drop support for Python 2.7 in January 2021. More details about Python 2 support in pip can be found at https://pip.pypa.io/en/latest/development/release-process/#python-2-support
WARNING: The directory '/home/laurent/.cache/pip' or its parent directory is not owned or is not writable by the current user. The cache has been disabled. Check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Collecting xlwt
  Downloading xlwt-1.3.0-py2.py3-none-any.whl (99 kB)
     |████████████████████████████████| 99 kB 897 kB/s 
Installing collected packages: xlwt
Successfully installed xlwt-1.3.0
WARNING: You are using pip version 20.2; however, version 20.2.3 is available.
You should consider upgrading via the '/usr/bin/python -m pip install --upgrade pip' command.
laurent@Laurent-I7-9900K:~$ /usr/bin/python2 /home/laurent/Langages/python/2.7.6/Eric-mag/mag_5-3.py
Puis j'ai créer ma basse de données et la table avec phpmyadmin

et la ça fonctionne avec :
/usr/bin/python2 /home/laurent/Langages/python/2.7.6/Eric-mag/mag_5-3.py
Pouvez-vous m'expliquer pourquoi ?
Pourtant j'ai bien de "/usr/bin/python" l'executable de python
/usr/bin/python pointe vers python2.7 ?????
laurent@Laurent-I7-9900K:~$ ls -alh /usr/bin/python*
lrwxrwxrwx 1 root root    9 nov.  28  2019 /usr/bin/python -> python2.7
lrwxrwxrwx 1 root root    9 nov.  28  2019 /usr/bin/python2 -> python2.7
-rwxr-xr-x 1 root root 3,5M juil. 20 17:37 /usr/bin/python2.7
lrwxrwxrwx 1 root root   33 juil. 20 17:37 /usr/bin/python2.7-config -> x86_64-linux-gnu-python2.7-config
lrwxrwxrwx 1 root root   16 avril 16  2018 /usr/bin/python2-config -> python2.7-config
lrwxrwxrwx 1 root root    9 nov.  28  2019 /usr/bin/python3 -> python3.6
-rwxr-xr-x 2 root root 4,4M juil. 17 14:50 /usr/bin/python3.6
lrwxrwxrwx 1 root root   33 juil. 17 14:50 /usr/bin/python3.6-config -> x86_64-linux-gnu-python3.6-config
-rwxr-xr-x 2 root root 4,4M juil. 17 14:50 /usr/bin/python3.6m
lrwxrwxrwx 1 root root   34 juil. 17 14:50 /usr/bin/python3.6m-config -> x86_64-linux-gnu-python3.6m-config
lrwxrwxrwx 1 root root   16 oct.  25  2018 /usr/bin/python3-config -> python3.6-config
lrwxrwxrwx 1 root root   10 nov.  28  2019 /usr/bin/python3m -> python3.6m
lrwxrwxrwx 1 root root   17 oct.  25  2018 /usr/bin/python3m-config -> python3.6m-config
lrwxrwxrwx 1 root root   16 avril 16  2018 /usr/bin/python-config -> python2.7-config
laurent@Laurent-I7-9900K:~$ 
Merci.
Il manque le shebang en début de script. Donc lorsque tu l'exécute “tel quel”, le mauvais interpréteur est choisi (un shell). En forçant l'utilisation de python2 avec la syntaxe
python mon_script.py
ou
python2 mon_script.py
ça fonctionne car on passe le script au bon interpréteur (on suppose que python et python2 sont le même exécutable, ce qui est vrai sur ubuntu 18.04).

Pour pouvoir lancer “directement” ton script avec la syntaxe
./mon_script.py
il faut renseigner le shebang.

Donc il faut que la toute première ligne soit égale à
#!/usr/bin/python
et réessaye de le lancer comme tu le faisais avant.


Je rappelle que python2 est fini et qu'il est plus que temps de migrer vers python3. Je sais, c'est pas toujours évident mais à défaut de pouvoir migrer ce code-là en particulier, je t'invite à coder tout ce qui va autour en python3. Le shebang pour un script écrit en python3 sera alors
#!/usr/bin/python3
Re,

J'ai ajouté en première ligne
#!/usr/bin/python
puis executé comme je le fessais avant
python /home/laurent/Langages/python/2.7.6/Eric-mag/mag_5-3.py
ça fonctionne

Je vous remercie.
Super.
SVP ajoutez “[RÉSOLU]” dans le titre de la discussion (titre modifiable à partir du premier message).