您好,登录后才能下订单哦!
这篇文章给大家分享的是有关Python找不到ssl模块怎么办的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
python安装完毕后,提示找不到ssl模块:
[www@pythontab.com ~]$ python Python 2.7.15 (default, Oct 23 2018, 18:08:43) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] 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 "/usr/local/python27/lib/python2.7/ssl.py", line 60, in <module> import _ssl # if we can't import it, let the error propagate ImportError: No module named _ssl >>>
解决方法:
1. 查看openssl安装包,发现缺少openssl-devel包
[www@pythontab.com ~]$ rpm -aq|grep openssl openssl-0.9.8e-20.el5 openssl-0.9.8e-20.el5 [www@pythontab.com ~]$
2. yum安装openssl-devel
[www@pythontab.com ~]$ yum install openssl-devel -y #查看安装结果 [www@pythontab.com ~]$ rpm -aq|grep openssl openssl-devel-1.0.1e-57.el6.x86_64 openssl-1.0.1e-57.el6.x86_64
3. 重新编译python
修改Setup文件
vi /src/Python-2.7.15/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
4. 重新编译
进入源码目录,重新编译安装
[www@pythontab.com ~]$ cd /src/Python-2.7.15/ [www@pythontab.com ~]$ make [www@pythontab.com ~]$ make install
5. 测试,已可正常使用。
[www@pythontab.com ~]$ python Python 2.7.15 (default, Oct 23 2018, 19:08:43) [GCC 4.4.7 20120313 (Red Hat 4.4.7-23)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import ssl >>>
注:如需保留旧版本的就不需要执行 6 .7两部
6 重命名旧版本的python依赖
ll /usr/bin | grep python mv /usr/bin/python /usr/bin/python2.7
7 删除旧的软链接,创建新的软链接到最新的python
rm -rf /usr/bin/python ln -s /usr/local/bin/python3.6 /usr/bin/python python -V
使用yum命令报错File "/usr/bin/yum", line 30 except KeyboardInterrupt, e:
问题出现原因:
yum包管理是使用python2.x写的,将python2.x升级到python3.1.3以后,由于python版本语法兼容性导致问题出现
解决办法:
修改yum配置文件,将python版本指向以前的旧版本
# vi /usr/bin/yum #!/usr/bin/python2.7 修改urlgrabber-ext-down文件,更改python版本 # vi /usr/libexec/urlgrabber-ext-down #!/usr/bin/python2.7 Could not fetch URL https://pypi.python.org/simple/six/: There was a problem confirming the ssl certificate: Can't connect to HTTPS URL because the SSL module is not available. - skipping
如需安装pip
下载相关文件
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
执行
/usr/local/python/bin/python3 get-pip.py
添加环境变量
vim ~/.bash_profile
添加下面这条参数
export PATH=/usr/local/python/bin:$PATH
保存
source ~/.bash_profile
测试
执行
[root@huo ~]# python3 Python 3.6.5 (default, Apr 1 2018, 20:41:34) [GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>
执行脚本如下:
vim install_python.sh
#!/bin/bash echo "正在安装相关组件" yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc-c++ gcc openssl-devel echo "下载安装包" wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz echo "正在解压安装包" tar -xf Python-3.6.5.tgz -C /root/ && cd /root/Python-3.6.5/ echo "添加ssl支持" cat >> /root/Python-3.6.5/Modules/Setup.dist <<"EOF" _socket socketmodule.c SSL=/usr/local/ssl _ssl _ssl.c \ -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \ -L$(SSL)/lib -lssl -lcrypto EOF echo "正在编译安装Python" ./configure --prefix=/usr/local/python && make && make install cd /root echo "删除安装包" rm -rf /root/Python-3.6.5.tgz && rm -rf /root/Python-3.6.5 echo "正在添加环境变量" echo "export PATH=/usr/local/python/bin:$PATH">> ~/.bash_profile source ~/.bash_profile echo "安装完成,请执行python3进行测试"
感谢各位的阅读!关于“Python找不到ssl模块怎么办”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。