Linux under the default system comes with python2.6 version, this version is dependent on many programs of the system, so it is not recommended to delete, if using the latest Python3 then we know that the compilation and installation of the source package and the system default package is not any impact, so you can install Python3 and python2 coexistence
First go to the Python official website download Python3 source package, Website: https://www.python.org/
Go in and click on the navigation bar downloads, you can also put the mouse on the downloads pop-up menu to select Source code, is the source code package meaning, Choose the latest version of 3.5.1 here, of course, there are many other historical versions, click on the page below you can see the download link, including the source package, Mac OSX installation package, Windows installation package
Here choose the first download, download is the source package: python-3.5.1.tgz, download and upload to the server, start to prepare for installation
Release files:
Tar-xvzf python-3.5.1.tgz
Enter directory:
CD PYTHON-3.5.1/
To add a configuration:
./configure--prefix=/usr/python
Here Configure your own installation directory, then compile the source code:
Make
To perform the installation:
Make install
The entire process is approximately 5-10 minutes, and after the installation is successful, the installation directory is/usr/python
The original python in the system is in/usr/bin/python, ls-l can see that Python is a soft link to the python2.6 in this directory
We can either delete this or create a new Python3 soft link, except that Python will change to Python3 when executed, or the Python script header declaration will be changed to #!/usr/bin/python3
In order to facilitate the suggestion to rename first, and then create a soft link on it, the previous program head does not have to change:
$ mv/usr/bin/python/usr/bin/python.bak$ ln-s/usr/python/bin/python3/usr/bin/python
This is established, and then directly execute the Python command, the equivalent of calling Python3, in fact, Python3 is also a soft link, link to python3.5.1, this multiple links actually does not affect, mainly for the version upgrade more convenient, do not change the version number
Python3 new version of the installation is these, do not uninstall the old version, the new version is also normal use
Missing C + + compiler, perform the following command installation:
Yum Install gcc-c++
How to install Python3 in CentOS