Operations 7 min read

Step-by-Step Guide to Installing Python 3 on CentOS 7 and Avoiding Common Pitfalls

Learn how to install Python 3 on a CentOS system by preparing dependencies, downloading source, configuring, compiling, and setting up environment variables, followed by a checklist to verify the installation and a troubleshooting guide for common errors such as missing compilers, zlib, SSL, and multilib conflicts.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Step-by-Step Guide to Installing Python 3 on CentOS 7 and Avoiding Common Pitfalls

Installing Python 3 on CentOS

This guide walks through the complete process of installing Python 3 from source on a CentOS machine, covering prerequisite libraries, source acquisition, compilation, environment configuration, verification, and common pitfalls.

1. Install prerequisite libraries

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel

2. Download the Python 3 source code

You can obtain the source either from the official download page or directly via wget:

https://www.python.org/downloads/source/
wget https://www.python.org/ftp/python/3.6.1/Python-3.6.1.tgz

3. Create the installation directory

Choose a location for the custom Python installation, for example:

mkdir -p /usr/local/python3

4. Extract the source archive

tar -zxvf Python-3.6.1.tgz

5. Configure and compile the source

cd Python-3.6.1
./configure --prefix=/usr/local/python3
make
make install

6. Create a symbolic link for easy access

ln -s /usr/local/python3/bin/python3 /usr/bin/python3

7. Add the new binary directory to PATH

Edit ~/.bash_profile and append:

# Add custom Python3 to PATH
PATH=$PATH:$HOME/bin:/usr/local/python3/bin
export PATH

Save the file (Esc, :wq) and reload the profile.

8. Verify the installation

[user@host ~]$ python3 -V
Python 3.6.1
[user@host ~]$ pip3 -V
pip 9.0.1 from /usr/local/lib/python3.6/site-packages (python 3.6)

Common Pitfalls and Solutions

Pitfall 1: configure: error: no acceptable C compiler found in $PATH

Install the GCC compiler:

yum install -y gcc

Pitfall 2: zipimport.ZipImportError: can’t decompress data

Missing zlib development package; install it and recompile:

yum -y install zlib*

Pitfall 3: pip3: Can't connect to HTTPS URL because the SSL module is not available

Configure with SSL support:

cd Python-3.6.2
./configure --with-ssl
make
sudo make install

Pitfall 4: Multilib version conflicts

Identify duplicate library versions (e.g., openssl) and remove the unwanted one:

# rpm -qa | grep openssl
openssl-devel-1.0.0-27.el6_4.2.x86_64
openssl-1.0.0-27.el6_4.2.x86_64
openssl-1.0.0-27.el6_4.2.i686
# Remove the i686 package
rpm --erase --nodeps openssl-1.0.0-27.el6_4.2.i686
# Update remaining package
yum update "openssl*"

After resolving the conflict, re‑run the Python build steps.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythonCompilationLinuxtroubleshooting
Liangxu Linux
Written by

Liangxu Linux

Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.