Transferred from: https://www.cnblogs.com/terryguan/p/7233801.html
View the Python version in the current system
Python--version
Returns Python 2.6.6 as normal.
Check the CentOS version
Cat/etc/redhat-release
Return to CentOS release 6.9 (Final) as normal.
Install all the development kits
Yum groupinstall-y "Development tools"
Install additional required Packages
Yum install-y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel
Download, compile, and install Python 2.7.13
wget Https://www.python.org/ftp/python/2.7.13/Python-2.7.13.tgztar zxf python-2.7.13.tgzcd python-2.7.13./ Configuremake && make Install
The default Python 2.7.13 is installed in the/usr/local/bin directory.
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 system default Python version
Rename the Legacy Python version of the system by default.
Mv/usr/bin/python/usr/bin/python.old
Then delete the system default Python-config soft link.
Rm-f/usr/bin/python-config
Finally, create a new version of the Python soft link.
Ln-s/usr/local/bin/python/usr/bin/pythonln-s/usr/local/bin/python-config/usr/bin/python-configln-s/usr/local/ include/python2.7//usr/include/python2.7
After the above steps are done, the Python under 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
Returns Python 2.7.13 as normal.
The following steps are still necessary
Install Setuptools for new Python
wget Https://bootstrap.pypa.io/ez_setup.py-O-| Python
Once the setuptools is properly installed, the Easy_install command will be installed in the/usr/local/bin directory.
Install PIP for new Python
Easy_install pip
The PIP command will be installed in the/usr/local/bin directory after the correct installation is complete.
Install distribute package for new Python (optional)
Pip Install Distribute
At this point, the new Python is ready to install.
Note: This may cause a previously installed Python program to run or not be restarted (such as the famous Shadowsocks python version). The reason is that the older version of Pkg_resources is located under/usr/lib/python2.6/site-packages. And the new version is under the/usr/local/lib/python2.7/site-packages.
So maybe you need to reinstall the program.
Note again: upgrading Python may result in the Yum command being unavailable. Here's how to fix it:
Edit the/usr/bin/yum file, starting with the first line of
#!/usr/bin/python
Switch
#!/usr/bin/python2.6
However, this change, in case you yum update a bit, Yum has been upgraded, and then back to the same old.
So, after my unremitting pondering and efforts, found a way (online solutions are copied to copy, not a little eggs).
Remember that the important path to the old version of Python 2.6.6 is as follows, when running the Yum command, you will be prompted which module does not exist, we will go to the old version of the path to find, we will be able to find. Once found, copy to the new version of Python under the path/usr/local/lib/python2.7/site-packages/.
/usr/lib/python2.6/site-packages//usr/lib64/python2.6/site-packages/
My copy process is this:
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/
The CentOS upgrade system comes with a python2.6 of python2.7