Skip to content

Instantly share code, notes, and snippets.

@zobayer1
Last active September 14, 2024 09:43
Show Gist options
  • Save zobayer1/8f1477af1d6152671824ca737143ea75 to your computer and use it in GitHub Desktop.
Save zobayer1/8f1477af1d6152671824ca737143ea75 to your computer and use it in GitHub Desktop.
Install Python 3.6, 3.7, 3.8 in your Fedora system

Python 3.9 comes as a default with Fedora 34. However, sometimes you may wish to install older versions for development and test purposes. Apart from groupinstall command, these instructions work for CentOS and REHL systems as well.

Prerequisites

Install python development dependencies.

sudo dnf groupinstall "Development Tools"
sudo dnf install python3-devel openssl-devel zlib-devel bzip2-devel sqlite-devel libffi-devel

Note: You will need to rebuild and reinstall if you install new source or development libraries for python. Do not create or modify symlinks for python, python3, etc, as that may and will break many dependent libraries in your system.

Install Python 3.8

Visit https://www.python.org/ftp/python/ for latest releases for version 3.8.X and download the .tgz file. We will install Python-3.8.11.

# download and extract source archive
wget https://www.python.org/ftp/python/3.8.11/Python-3.8.11.tgz
tar xzf Python-3.8.11.tgz Python-3.8.11/
cd Python-3.8.11/
# configure with all optimizations
./configure --enable-optimizations --with-ensurepip=install
# do not touch system default python
sudo make altinstall
# cleanup
cd .. && sudo rm -rf Python-3.8.11/

You can remove the .tgz file, or keep it for future re-installation.

Install Python 3.7

Visit https://www.python.org/ftp/python/ for latest releases for version 3.7.X and download the .tgz file. We will install Python-3.7.10.

# download and extract source archive
wget https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz
tar xzf Python-3.7.10.tgz Python-3.7.10/
cd Python-3.7.10/
# configure with all optimizations
./configure --enable-optimizations --with-ensurepip=install
# do not touch system default python
sudo make altinstall
# cleanup
cd .. && sudo rm -rf Python-3.7.10/

You can remove the .tgz file, or keep it for future re-installation.

Install Python 3.6

Due to some changes in memory allocation architecture, installation of ensurepip usually fails with gcc 11. An older gcc or clang is required. Install clang dependencies:

sudo dnf install clang llvm-devel

Visit https://www.python.org/ftp/python/ for latest releases for version 3.6.X and download the .tgz file. We will install Python-3.6.13.

# download and extract source archive
wget https://www.python.org/ftp/python/3.6.13/Python-3.6.13.tgz
tar xzf Python-3.6.13.tgz Python-3.6.13/
cd Python-3.6.13/
# configure with all optimizations
CC=clang LLVM_PROFDATA=/usr/bin/llvm-profdata ./configure --enable-optimizations --with-ensurepip=install
# do not touch system default python
CC=clang sudo make altinstall
# cleanup
cd .. && sudo rm -rf Python-3.6.13/

You can remove the .tgz file, or keep it for future reinstallations.

Other versions of Python 3

Follow similar process as above.

@fdolatsh
Copy link

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment