Centos7 is installed with python2.7.5 by default. for example, yum uses python2.7.51 & ndash. download the python3.5 package on the python official website. In fact, one of the following two packages can use Pyth Centos7 to install python2.7.5 by default. because some commands use it, for example, yum, it uses python2.7.51-download the package of python3.5.
Https://www.python.org/downloads/release/python-351/ at python official website
Download the tgz package. In fact, either of the following two packages can be used.
Python-3.5.1.tgz (this is not compiled, can not be decompressed directly use)
Python-3.5.1.tar.xz (this is pthon source code)
2-decompress the file
tar -xf Python-3.5.1.tgz
3-decompress the package and enter the Python-3.5.1 directory.
cd Python-3.5.1
4-start installation and use the compilation method for installation
There is a README file in the python directory, which describes how to install python. However, we need to specify the installation directory.
mkdir /usr/python3.5./configure --prefix=/usr/python3.5makemake install
Note: after the/configure command is executed, create a file creating Makefile for the following make command to install the program in the specified directory after running make install.
5-use Python 3.5.1 by default
Python, python2, and python2.7 files in/usr/bin point to the latter in sequence.
cd /usr/bin mv python python.bak ln -s /usr/python3.5/bin/python3 /usr/bin/python
Note that after compilation and installation, a python3 connection is automatically generated under/usr/python3.5/bin, which points to python3.5 in the bin directory.
6-because yum uses python2, replacing it with python3 may not work properly. continue to use this python2.7.5
Therefore, modify the yum configuration file (sudo vi/usr/bin/yum ). #! /Usr/bin/python #! /Usr/bin/python2.7 save and exit.