Operations 6 min read

Step-by-Step Guide to Installing Python 3.6.5 on Linux (with Troubleshooting)

This tutorial walks through checking the default Python version on a Linux system, locating its binaries, downloading Python 3.6.5 source, installing required build dependencies, compiling and installing Python, creating symlinks, and configuring environment variables, while also addressing common network and repository issues.

Open Source Linux
Open Source Linux
Open Source Linux
Step-by-Step Guide to Installing Python 3.6.5 on Linux (with Troubleshooting)

Based on the Linux distribution shown in the image, the system already includes Python 2.7.5.

1. Verify the existing Python version with the command python --version. The output confirms Python 2.7.5, and the interpreter can be entered with python (exit with Ctrl+D).

2. Locate the default Python binaries. Both /usr/bin/python and /usr/bin/python2 are symbolic links ultimately pointing to /usr/bin/python2.7, so python, python2 and python2.7 are equivalent.

3. Install Python 3:

(1) Download the source package from https://www.python.org/downloads/source/; for example, Python 3.6.5.

(2) Upload the Python-3.6.5.tgz file to a directory on the Linux host, such as /root/tools.

(3) Extract the archive with tar -zxvf Python-3.6.5.tgz.

(4) Install the required build dependencies:

yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gcc make

If using Python 3.7, also install libffi-devel. The installation should complete in about one minute.

If the yum command fails due to network issues, edit the network interface configuration (e.g., /etc/sysconfig/network-scripts/ifcfg-ens33) with appropriate settings and restart the network service before retrying the yum command.

(5) Compile and install Python:

./configure --prefix=/root/training/Python-3.6.5
make
make install

The --prefix option sets the installation directory. After installation, setuptools and pip are also installed under /root/training/Python-3.6.5.

(6) Create a symbolic link for the new Python binary in /usr/local/bin so it can be invoked as python3 without removing the existing Python 2.7.

Running python3 now starts the newly installed interpreter, while the original python / python2 commands still refer to Python 2.7.

(7) Configure environment variables to use pip3 easily. Edit ~/.bash_profile and add:

# Configure Python
export PYTHON_HOME=/root/training/Python-3.6.5
export PATH=$PYTHON_HOME/bin:$PATH

Source the profile with source ~/.bash_profile and verify the configuration using echo $PYTHON_HOME and python3 --version.

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.

PythonCompilationLinuxInstallationSystem Administration
Open Source Linux
Written by

Open Source Linux

Focused on sharing Linux/Unix content, covering fundamentals, system development, network programming, automation/operations, cloud computing, and related professional knowledge.

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.