Je souhaite installer la dernière archive tar Python sur Ubuntu, téléchargée depuis lien .
Est-ce une bonne façon d'installer?
./configure
make
make install
Sinon, comment puis-je le faire?
D'abord, installez des dépendances:
sudo apt-get install build-essential checkinstall
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Puis téléchargez en utilisant la commande suivante:
version=2.7.13
cd ~/Downloads/
wget https://www.python.org/ftp/python/$version/Python-$version.tgz
Extraire et aller dans le répertoire:
tar -xvf Python-$version.tgz
cd Python-$version
Maintenant, installez en utilisant la commande que vous venez d’essayer, en utilisant plutôt checkinstall
pour faciliter la désinstallation si nécessaire:
./configure
make
sudo checkinstall
Remplacez version
par la version dont vous avez besoin ( version=2.7.1
ou version=3.6.0
, par exemple).
À moins que vous ne souhaitiez vraiment le compiler vous-même, la méthode préférée consiste à utiliser le PPA DeadSnakes installer les versions de Python non incluses par défaut:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python2.7
D'autres versions, telles que python2.4
ou python3.6
, etc. sont également disponibles.
Continuant à documenter ceci pour les dernières versions d’Ubuntu 1 : pour le serveur Ubuntu 16.04.1, le Python par défaut est la version 3.5, et Python 2.7 n'est pas installé par défaut . Sur une nouvelle installation (notez qu'il n'y a même pas d'exécutable python
):
$ type python3 python2 python
python3 is /usr/bin/python3
-bash: type: python2: not found
-bash: type: python: not found
$ python3 --version
Python 3.5.2
$ python --version
The program 'python' can be found in the following packages:
* python-minimal
* python3
Try: sudo apt install <selected package>
Note: avant de continuer, vous voudrez probablement faire un rapide sudo apt-get update
, sudo apt-get upgrade
et sudo apt-get dist-upgrade
(veuillez noter exactement ce que font ces commandes; je suppose qu’une nouvelle installation est ici. )
L'installation de python 2.7 est aussi simple que:
$ sudo apt-get install python2.7
La sortie initiale de l'installation de python 2.7 est la suivante:
$ sudo apt-get install python2.7
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libpython2.7-minimal libpython2.7-stdlib python2.7-minimal
Suggested packages:
python2.7-doc binutils binfmt-support
The following NEW packages will be installed:
libpython2.7-minimal libpython2.7-stdlib python2.7 python2.7-minimal
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
Need to get 3,735 kB of archives.
After this operation, 15.8 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...etc, etc...
Après l'installation de python 2.7,
$ type python3 python2.7 python3.5 python2 python
python3 is /usr/bin/python3
python2.7 is /usr/bin/python2.7
python3.5 is /usr/bin/python3.5
bash: type: python2: not found
bash: type: python: not found
Mais il y a toujours un problème, puisque vous ne pouvez pas encore installer les modules PyPI via pip
- par exemple, si vous voulez un notebook jupyter, ou le dernier scipy ou numpy (etc), vous voudrez installer pip
puis pip install
ceux-ci, et toujours vers apt-get
pour installer les dépendances système nécessaires, comme les bibliothèques graphviz ou de base du système.
$ type pip3 pip2 pip
bash: type: pip3: not found
bash: type: pip2: not found
bash: type: pip: not found
$ python3 -m pip --version
/usr/bin/python3: No module named pip
Donc, pour installer pip, encore une fois, c'est aussi simple que sudo apt-get install python-pip
:
$ sudo apt-cache search -n pip | egrep '^python[0-9]*-pip'
python-pip - alternative Python package installer
python-pip-whl - alternative Python package installer
python3-pip - alternative Python package installer - Python 3 version of the package
Vous aurez besoin à la fois de python-pip
pour Python 2,7 pip
et de python3-pip
pour Python 3 pip
. L'installation via apt-get
est sûre d'installer les dépendances requises; Par exemple, voici la sortie pour installer pip2:
$ sudo apt-get install python-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
binutils build-essential dpkg-dev fakeroot g++ g++-5 gcc gcc-5 libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan2 libatomic1 libc-dev-bin libc6-dev
libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-5-dev
libgomp1 libitm1 liblsan0 libmpx0 libpython-all-dev libpython-dev libpython-stdlib libpython2.7
libpython2.7-dev libquadmath0 libstdc++-5-dev libtsan0 libubsan0 linux-libc-dev make
manpages-dev python python-all python-all-dev python-dev python-minimal python-pip-whl
python-pkg-resources python-setuptools python-wheel python2.7-dev
Suggested packages:
binutils-doc debian-keyring g++-multilib g++-5-multilib gcc-5-doc libstdc++6-5-dbg gcc-multilib
autoconf automake libtool flex bison gdb gcc-doc gcc-5-multilib gcc-5-locales libgcc1-dbg
libgomp1-dbg libitm1-dbg libatomic1-dbg libasan2-dbg liblsan0-dbg libtsan0-dbg libubsan0-dbg
libcilkrts5-dbg libmpx0-dbg libquadmath0-dbg glibc-doc libstdc++-5-doc make-doc python-doc
python-tk python-setuptools-doc
The following NEW packages will be installed:
binutils build-essential dpkg-dev fakeroot g++ g++-5 gcc gcc-5 libalgorithm-diff-perl
libalgorithm-diff-xs-perl libalgorithm-merge-perl libasan2 libatomic1 libc-dev-bin libc6-dev
libcc1-0 libcilkrts5 libdpkg-perl libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-5-dev
libgomp1 libitm1 liblsan0 libmpx0 libpython-all-dev libpython-dev libpython-stdlib libpython2.7
libpython2.7-dev libquadmath0 libstdc++-5-dev libtsan0 libubsan0 linux-libc-dev make
manpages-dev python python-all python-all-dev python-dev python-minimal python-pip
python-pip-whl python-pkg-resources python-setuptools python-wheel python2.7-dev
0 upgraded, 49 newly installed, 0 to remove and 0 not upgraded.
Need to get 61.1 MB of archives.
After this operation, 169 MB of additional disk space will be used.
Do you want to continue? [Y/n] Y
...etc...
Une chose intéressante se produit à la suite de cela: vous avez maintenant le "standard" (et le PEP recommandé) python2
et python3
(qui ne sont que des liens symboliques vers python 2.7 et python 3.5):
$ type python3 python2 python python2.7 python3.5
python3 is /usr/bin/python3
python2 is /usr/bin/python2
python is /usr/bin/python
python2.7 is /usr/bin/python2.7
python3.5 is /usr/bin/python3.5
Vous voudrez aussi sudo apt-get install python3-pip
; avant d’installer, vous avez:
$ type pip pip2 pip3
pip is /usr/bin/pip
pip2 is /usr/bin/pip2
-bash: type: pip3: not found
$ python2 -m pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ python3 -m pip --version
/usr/bin/python3: No module named pip
Après avoir installé pip3
,
$ sudo apt-get install python3-pip
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
libpython3-dev libpython3.5-dev python3-dev python3-setuptools python3-wheel python3.5-dev
Suggested packages:
python-setuptools-doc
The following NEW packages will be installed:
libpython3-dev libpython3.5-dev python3-dev python3-pip python3-setuptools python3-wheel python3.5-dev
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 38.0 MB of archives.
After this operation, 55.2 MB of additional disk space will be used.
Do you want to continue? [Y/n]
...etc...
Les versions résultantes:
$ type python python2 python3 pip pip2 pip3
python is /usr/bin/python
python2 is hashed (/usr/bin/python2)
python3 is hashed (/usr/bin/python3)
pip is /usr/bin/pip
pip2 is /usr/bin/pip2
pip3 is /usr/bin/pip3
$ pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ pip3 --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
$ python2 -m pip --version
pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)
$ python3 -m pip --version
pip 8.1.1 from /usr/lib/python3/dist-packages (python 3.5)
Et une dernière chose avant de commencer à installer tous vos modules Python PyPI préférés: vous devrez probablement mettre à jour pip lui-même (à la fois pip2 et pip3, séparément, peu importe si pip
est invoqué via les exécutables python
ou les exécutables pip
, les mises à niveau réelles sont stockées dans /usr/lib
):
$ sudo -H python2 -m pip install --upgrade pip
...
$ sudo -H python3 -m pip install --upgrade pip
...
Vous pouvez maintenant exécuter pip
ou la version groupée dans python
(via python -m pip {command}
).
[1] Récapitulatif historique: Ubuntu plus ancien n'avait que Python 2.6, donc toutes les différentes méthodes pour installer Python 2.7+. Plus tard, après avoir ajouté Python 2.7 aux référentiels publics, nous avions toujours le même défi pour installer le dernier Python 2.7 avec les derniers correctifs, ce qui était (trop) souvent nécessaire. La situation actuelle est bien meilleure / plus simple: l'actuel Python 2.7 & amp; 3.5 (essentiellement les deux seules versions de la plate-forme Python qui intéressent le plus) qui sont maintenant dans les dépôts publics sont très stables, donc maintenant nous n'avons plus qu'à nous soucier d'installer les derniers modules python , pas les derniers < em> python . Donc, maintenant, le "problème de la dernière version" de Python a déplacé en partie hors du repo du système d’exploitation; apt
et dans PyPI & amp; pip
.)
12.04
Si vous suivez la réponse de Achu , le terme libread5-dev
doit être remplacé par libreadline-gplv2-dev
. Donc, la commande complète serait:
sudo apt-get install libreadline-gplv2-dev libncursesw5-dev libssl-dev libsqlite3-dev tk-dev libgdbm-dev libc6-dev libbz2-dev
Vous pouvez également le télécharger et l’installer via pyenv
#Install Pyenv
git clone https://github.com/pyenv/pyenv.git ~/.pyenv
export PATH=~/.pyenv/bin:/usr/local/hadoop/bin/:$PATH
echo 'export PYENV_ROOT="~/.pyenv"' >> ~/.bash_profile
echo 'export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(pyenv init -)"' >> ~/.bash_profile
#Install Python
pyenv install 2.7.8
pyenv global 2.7.8
pyenv install 3.4.5
pyenv global 3.4.5
Lire d'autres questions sur les étiquettes software-installation python