View the Python version in the current system
Python -- version
Python 2.6.6 is returned as normal.
Check CentOS version
Cat/etc/redhat-release
The CentOS release 6.8 (Final) is returned as normal.
Install all development kits
Yum groupinstall-y "Development tools"
Install other required packages
The yum install-y zlib-devel bzip2-devel openssl-devel ncurses-devel
Download, compile, and install Python 2.7.12
Wget https://www.python.org/ftp/python/2.7.12/Python-2.7.12.tgz
Tar zxf Python-2.7.12.tgz
Cd Python-2.7.12
./Configure
Make & make install
Python 2.7.12 is installed in the/usr/local/bin directory by default.
Ll-tr/usr/local/bin/python *
/Usr/local/bin/python2.7
/Usr/local/bin/python2.7-config
/Usr/local/bin/python-> python2
/Usr/local/bin/python2-> python2.7
/Usr/local/bin/python2-config-> python2.7-config
/Usr/local/bin/python-config-> python2-config
The Python that comes with the system is in the/usr/bin directory.
Ll-tr/usr/bin/python *
/Usr/bin/python2.6-config
/Usr/bin/python2.6
/Usr/bin/python
/Usr/bin/python2-> python
/Usr/bin/python-config-> python2.6-config
Update the default Python version.
First, rename the default old Python version.
Mv/usr/bin/python. old
Delete the default python-config soft link.
Rm-f/usr/bin/python-config
Finally, create a new version of Python soft link.
Ln-s/usr/local/bin/python/usr/bin/python
Ln-s/usr/local/bin/python-config/usr/bin/python-config
Ln-s/usr/local/include/python2.7 // usr/include/python2.7
After the above steps are completed, the Python in the directory/usr/bin should be
Ll-tr/usr/bin/python *
/Usr/bin/python2.6-config
/Usr/bin/python2.6
/Usr/bin/python. old
/Usr/bin/python2-> python
/Usr/bin/python->/usr/local/bin/python
/Usr/bin/python-config->/usr/local/bin/python-config
View the new Python version
Python -- version
Python 2.7.12 is returned as normal.
The following steps are necessary:
Install setuptools for the new Python version
Wget https://bootstrap.pypa.io/ez_setup.py-O-| python
After setuptools is correctly installed, the easy_install command will be installed in the/usr/local/bin directory.
Install pip for the new Python version
Easy_install pip
After correct installation, the pip command will be installed in the/usr/local/bin directory.
Install the distribute package for the new Python version (optional)
Pip install distribute
Now, the new version of Python is installed.
Note: this may cause the previously installed Python program to fail or cannot be restarted (for example, the famous Shadowsocks Python version ). The reason is that the old version of pkg_resources is located in/usr/lib/python2.6/site-packages. The new version is in/usr/local/lib/python2.7/site-packages.
Therefore, you may need to reinstall the program.
Note: upgrading Python may make the yum command unavailable. The solution is as follows:
Edit the/usr/bin/yum file.
#! /Usr/bin/python
Change
#! /Usr/bin/python2.6
However, if you update yum one day, the upgrade of yum will change to the old one.
Therefore, after my unremitting efforts and efforts, I found a solution (the online solutions are copied and copied without any use ).
Remember the important path of the earlier version of Python 2.6.6 as follows. When running the yum command, you will be prompted which module does not exist. If it does not exist, we will find it under the earlier version path, certainly. Find the path and copy it to/usr/local/lib/python2.7/site-packages/of the new Python version.
/Usr/lib/python2.6/site-packages/
/Usr/lib64/python2.6/site-packages/
My replication process is as follows:
Cp-r/usr/lib/python2.6/site-packages/yum/usr/local/lib/python2.7/site-packages/
Cp-r/usr/lib/python2.6/site-packages/rpmUtils/usr/local/lib/python2.7/site-packages/
Cp-r/usr/lib/python2.6/site-packages/iniparse/usr/local/lib/python2.7/site-packages/
Cp-r/usr/lib/python2.6/site-packages/urlgrabber/usr/local/lib/python2.7/site-packages/
Cp-r/usr/lib64/python2.6/site-packages/rpm/usr/local/lib/python2.7/site-packages/
Cp-r/usr/lib64/python2.6/site-packages/curl/usr/local/lib/python2.7/site-packages/
Cp-p/usr/lib64/python2.6/site-packages/pycurl. so/usr/local/lib/python2.7/site-packages/
Cp-p/usr/lib64/python2.6/site-packages/_ sqlitecache. so/usr/local/lib/python2.7/site-packages/
Cp-p/usr/lib64/python2.6/site-packages/sqlitecachec. py/usr/local/lib/python2.7/site-packages/
Cp-p/usr/lib64/python2.6/site-packages/sqlitecachec. pyc/usr/local/lib/python2.7/site-packages/
Cp-p/usr/lib64/python2.6/site-packages/sqlitecachec. pyo/usr/local/lib/python2.7/site-packages/