1. get python2.7 download file
https://www.python.org/downloads/
2. tar xf Python2.7.xx.tar.gz
3. cd Python2.7.xx
# ./configure --prefix=/usr/local
# make && make altinstall (据说这个make altinstall 可以覆盖之前的Python版本,我试了好像没什么卵用 )
如果编译过程中出现C编译依赖错误,可以执行如下命令:
yum groupinstall "Development tools"
4. link the newest version
# unlink /usr/bin/python (一般是系统会安装2.6的版本,并创建了软连接,这里要首先解除原来的软连接)
# link -s /usr/local/bin/python2.7 /usr/bin/python
5. test
# python
6. problem
Python 2.7.10 (default, Oct 29 2015, 04:13:03) [GCC 3.4.5 20051201 (Red Hat 3.4.5-2)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ssl Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/home/bae/nanxiu/software/Python-2.7.10/Lib/ssl.py", line 97, in <module> import _ssl # if we can't import it, let the error propagate ImportError: No module named _ssl
yum install openssl-devel
然后需要重新编译安装python
参考链接:https://bugs.python.org/issue25526