Publish: 2018-07-21 | Modify: 2018-07-21
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.
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
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/
I come from China and I am a freelancer. I specialize in Linux operations, PHP, Golang, and front-end development. I have developed open-source projects such as Zdir, ImgURL, CCAA, and OneNav.