检查当前的版本 [root@node1 ~]# python -V Python 2.7.5 建立安装目录(自定义) [root@node1 Python-3.7.1]# mkdir /usr/local/python3 从官网下载python3的压缩包,解压(以3.7.1版本为例) # wget https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tgz # tar zxf Python-3.7.1.tgz cd 进入解压目录,而后 # cd Python-3.7.1 # ./configure --prefix=/usr/local/python3/ # make && make install cd 进入/usr/bin 其中有python、python二、python2.7三个文件依次指向后者。 备份当前默认版本python,若是有须要还可还原: # sudo mv python python.bak 建立python3.7的新连接(也可创建python3命令以区分,同mac),这样默认的python版本就替换为python3.7了 # ln -s /usr/local/python3/bin/python3.7 /usr/bin/python 检查当前默认python版本 # python -v 因为yum使用python2,替换为python3后没法正常工做, 所以修改yum配置文件: # sudo vi /usr/bin/yum 将第一行指定的python版本改成python2.7: *#!/usr/bin/python 改成 #!/usr/bin/python2.7 修改urlgrabber配置文件(网上不少教程都漏了这一步) # sudo vi /usr/libexec/urlgrabber-ext-down 同yum,把头部的python改为python2.7 连接:https://www.jianshu.com/p/74227d7ae6a6
Python安装完毕后,提示找不到ssl模块:node
(<http://blog.csdn.net/qq_25560423/article/details/62055497>;)python
例如这样: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available. Collecting xxx Could not fetch URL <https://pypi.python.org/simple/xxxx/>: There was a problem confirming the ssl certificate: Can’t connect to HTTPS URL because the SSL module is not available. - skipping Could not find a version that satisfies the requirement xxx (from versions: ) No matching distribution found for xxx
[root@localhost ~]# python2.7.5 linux
Python 2.7.5 (default, Jun 3 2013, 11:08:43) bash
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2 python2.7
Type “help”, “copyright”, “credits” or “license” for more information.socket
import ssl ide
Traceback (most recent call last): 测试
File “”, line 1, in fetch
File “/usr/local/python27/lib/python2.7/ssl.py”, line 60, in ui
import _ssl # if we can’t import it, let the error propagate
ImportError: No module named _ssl
查看openssl安装包,发现缺乏openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5
[root@localhost ~]#
yum安装openssl-devel
[root@localhost ~]# yum install openssl-devel -y
查看安装结果
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-26.el5_9.1
openssl-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
从新编译python
修改Setup文件
vi /usr/software/Python-2.7.5/Modules/Setup
修改为下面:
Socket module helper for socket(2) _socket socketmodule.c timemodule.c Socket module helper for SSL support; you must comment out the other socket line above, and possibly edit the SSL variable: SSL=/usr/local/ssl _ssl _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto
从新编译
make
make install
测试,已可正常使用。
[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 14:56:13)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type “help”, “copyright”, “credits” or “license” for more information.
import ssl
从新用pip安装