Compiling and Installing/One-Click Installation of Python 3 on CentOS 7

Publish: 2018-07-21 | Modify: 2018-07-21

Installing Python 3 on CentOS 7

python

Compiling and Installing Python 3

The latest version of Python is Python 3.7.0. Here is how you can compile and install Python 3.7.0 on CentOS 7:

# Install dependencies
yum -y install wget gcc gcc-c++ libffi-devel zlib-devel

# Download the source code (official)
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz

# If the download is slow, you can download it from the xiaoz software library
wget http://soft.xiaoz.org/python/Python-3.7.0.tar.xz

# Extract the source code
tar -xvJf Python-3.7.0.tar.xz

# Go into the extracted directory
cd Python-3.7.0

# Compile and install Python
./configure --prefix=/usr/local/python3 --enable-optimizations
make -j4 && make -j4 install

# Create symbolic links
ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3
ln -s /usr/local/python3/bin/pip3 /usr/bin/pip3

If everything goes smoothly, you can check the version of Python by running the command python3 -V. To use the original Python 2.7, simply use the command python xxx. The two versions will not interfere with each other.

version

One-click Installation of Python 3

Although compiling and installing Python is already quite simple, it can be time-consuming to manually enter the commands on multiple servers. To save time and effort, you can use the one-click script provided by xiaoz. Simply copy and run the following command:

wget https://raw.githubusercontent.com/helloxz/shell/master/python3.sh && sh python3.sh

one-click

Other Notes

The one-click installation script has only been tested on CentOS 7, but it should theoretically work on CentOS 6 as well. If you encounter any errors during installation, please search for the error message to see if any dependencies are missing. If you have any problems, please leave a comment for feedback.

Python official download address: https://www.python.org/ftp/python/


Comments