Python 3 Installation

Windows

Mainly two flavors on the Python web site.

Embeddable zip file

That is a portable installation that I don’t advise
I tried it with Python 3.9 and many issues. Several Python libraries are missing or fail to work(ex: traceback, venv…), pip is not installed and debugging with IntelliJ failed with that error message « ModuleNotFoundError No module named pydevd-bundle ».

Executable installer(.exe)

Take that ! All is working without any tweaks.

Linux

Also here two main flavors

Linux package manager

Simple and fast but available versions are limited.

apt

To install the default version provided by your package manager:
apt-get install -y python3.
To install a specific version available in the OS repo, specify that such as :
apt-get -y install python3=3.6.7-1~18.04.

You can install more recent versions or multiple pythons version by adding that external repository such as :

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.8 python3-pip

yum

To install the default version provided by your package manager:
yum install -y install python3.
To install a specific version available in the OS repo, specify that such as :
yum install -y install python3-3.6.7.

Gzipped source tarball

More long and complex but with that you can install any version of Python which you downloaded the gzip source code from the python website.

Yum for an alternative install :

yum install -y gcc make openssl-devel bizip2-devel libffi-devel zlib-devel
pwd == /tmp
tar -xvzf Python-3.8.7.tgz
cd Python-3.8.7
./configure
make altinstall
# python is now installed as a single file in /usr/local/python3.8

Common installation or update problem

Problem : at fresh install, the pip command fails because the distutils module is not found.

ImportError: No module named distutils.core

Solution : install distutils.
For example for python 3 :
sudo apt-get install python3-distutils

Problem : after adding a python alternative and switching to the last version (3.X -> 3.9), the pip command fails because an import from distutils module fails.

ImportError: cannot import name 'sysconfig' from 'distutils' (/usr/lib/python3.9/distutils/__init__.py)

Solution : check that the installed version of distutils is outdated for that new python version.
For example : apt list --installed | grep distutils
If there is not any 3.9 version, install the distutils 3.9.
Note : these distutils versions are not coupled packages and so these may be installed without the use of alternatives :
sudo apt install python3.9-distutils

Ce contenu a été publié dans Non classé. Vous pouvez le mettre en favoris avec ce permalien.

Laisser un commentaire

Votre adresse de messagerie ne sera pas publiée. Les champs obligatoires sont indiqués avec *