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.

@Ahmadkhan02
Copy link

helped!

@mor120
Copy link

mor120 commented Jan 2, 2023

Thanks!

@david-kariuki
Copy link

This is great

@zobayer1
Copy link
Author

If you are installing Python3.7+ on CentOS 7/8

You need openssl-1.1.1 at the very minimum. But the system has a lot of dependency on openssl-1.0.2. So it is advised to use a separate openssl installation.

First install openssl11 and openssl11-devel from epel.

# Install libraries
yum install openssl11 openssl11-devel

# Create directory for symlinks
mkdir /usr/local/openssl11 && cd "$_"
ln -s /usr/lib64/openssl11 lib
ln -s /usr/include/openssl11 include

Test that you did not touch the system's openssl (should be openssl-1.0.2*)

openssl version
openssl11 version

After that, before running python build scripts, update the configuration file:

cd /path/to/python/source/
sed -i 's/PKG_CONFIG openssl /PKG_CONFIG openssl11 /g' configure
./configure --enable-optimizations --with-ensurepip=install
make altinstall

See if python was installed successfully with openssl by running the following command that should not produce any errors.

python3.X -m SSL

Good luck.

@fdolatsh
Copy link

Thank you!

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