web-dev-qa-db-fra.com

Manière correcte d'installer python 2.7 sur Ubuntu 17.10?

Je me demandais comment installer correctement python2.7. Sur mon autre installation, zlib ne fonctionne pas et pip n’est pas installé correctement et j’ai été obligé d’utiliser python3 à partir de la ligne de commande.

J'ai une nouvelle installation d'Ubuntu 17.10 et j'aimerais pouvoir utiliser pip et d'autres choses. Je pense que c’est parce que python est déjà installé sur Ubuntu et j’en ai installé une autre version, car des outils de ligne de commande basés sur python comme la volatilité ont fonctionné.

Existe-t-il un moyen de résoudre ce problème afin que je puisse installer des modules et d'autres éléments ou utiliser le python déjà installé à partir de la ligne de commande?

32
user7853796

Pour installer Python2.7, vous devez simplement procéder comme suit dans Ubuntu 17.10 dans un terminal (ils fonctionnent parfaitement côte à côte dès la sortie de la boîte):

# refreshing the repositories
Sudo apt update
# its wise to keep the system up to date!
# you can skip the following line if you not
# want to update all your software
Sudo apt upgrade
# installing python 2.7 and pip for it
Sudo apt install python2.7 python-pip
# installing python-pip for 3.6
Sudo apt install python3-pip

NOTE: n'essayez pas de supprimer python 3.6 car cela risquerait de bousiller votre système

Vous pouvez appeler python pip de la manière suivante:

# for python 2.7
pip2 install <package>
# for python 3.6
pip install <package>

Utiliser pip sans numéro installerait les packages python 3.6.

56
Videonauth

Ma propre expérience de l'installation de Python et de tous les packages nécessaires. Testé sur Ubuntu 18.04 (non testé sur 17.10). Je peux me tromper, car je ne suis pas spécialiste d'Ubuntu.

Il est préférable d’utiliser la commande apt (apt-get) au lieu de la commande pip, car:

  1. apt installe uniquement testé sur les paquets et dépendances Ubuntu;
  2. La commande sudo apt update/upgrage maintient les paquets à jour;
  3. si vous souhaitez installer/mettre à jour des packages pour tous les utilisateurs de votre système Ubuntu, pas seulement pour votre propre compte local;
  4. si vous voulez des paquets pour Ubuntu, alors le système d’exploitation pourrait les utiliser aussi.

Pour les autres versions de packages, il convient d'utiliser l'environnement virtuel. Ou construisez et testez des packages à partir des codes sources (pour les spécialistes uniquement).

Ne supprimez pas le python3 actuel, sinon le système d'exploitation Ubuntu CASSERA.

# Refreshing the repositories
Sudo apt update
# Update software
Sudo apt upgrade

# Install Python and necessary packages.

# Install pip for 2.7 and then python 2.7 itself
Sudo apt install python-pip
Sudo apt install python2.7

# Install pip for 3.6
Sudo apt install python3-pip
# Install currently supported by Ubuntu python 3.x version.
Sudo apt install python3

# Don't delete current python3, otherwise Ubuntu OS will BROKE.
# Better don't install the newest versions 3.7, 3.8, 4.0, etc. on the whole OS (globally).
# This command works, but it's a bad idea to use it -- Sudo apt install python3.7
#     in this case import of numpy (import numpy) and other modules will fail for python3.7,
#     because 3.6 is the current (global) python version for Ubuntu, not 3.7.
# Use "Sudo apt install python3" not "Sudo apt install python3.7" command for python 3.x installation.
# If you need 3.7 or newer, use local virtual environment.
# It's a bad idea to have several versions of python 3.x globally at the same time.
# Use only currently supported by Ubuntu python 3.x version globally. At this moment it is 3.6.

# Install numpy, scipy, matplotlib, scikit-learn, scikit-image,
# opencv with contributions, pandas, pillow, psutil, spur, cython,
#ipython, jupyter, git.
Sudo apt install python-numpy
Sudo apt install python3-numpy
Sudo apt install python-scipy
Sudo apt install python3-scipy
Sudo apt install python-matplotlib
Sudo apt install python3-matplotlib
Sudo apt install python-sklearn
Sudo apt install python3-sklearn
Sudo apt install python-skimage
Sudo apt install python3-skimage
Sudo apt install python-opencv
Sudo apt install python3-opencv
Sudo apt install python-pandas
Sudo apt install python3-pandas
Sudo apt install python-pil
Sudo apt install python3-pil
Sudo apt install python-pil.imagetk  # if the imageTk import doesn't work
Sudo apt install python3-pil.imagetk  # if the imageTk import doesn't work
Sudo apt install python-psutil
Sudo apt install python3-psutil
Sudo apt install python-spur
Sudo apt install python3-spur
Sudo apt install cython
Sudo apt install cython3
Sudo apt install python-ipython
Sudo apt install python3-ipython
Sudo apt install ipython
Sudo apt install ipython3
Sudo apt install jupyter
Sudo apt install git

# To have both python 2 and 3 available on jupyter
Sudo apt install python-ipykernel
Sudo apt install python3-ipykernel

# To check installed packages use commands
python
# and
python3

# Then type in python 2 or 3 console
import numpy
import scipy
import matplotlib
import sklearn
import skimage
exit()

# To check ipython
ipython
exit
ipython3
exit

# To check jupyter run
jupyter notebook
# and check both version of python 2 and 3 in "New" menu

# To remove package (don't remove python3 -- it'll broke your Ubuntu)
Sudo apt purge --auto-remove packagename
# To search for the package:
apt search packagename

# Install PyCharm Community edition
Sudo snap install pycharm-community --classic
# To check PyCharm installation enter:
pycharm-community
2
foo bar