Python 3.7 安装完成后import ssl失败解决方法

提示找不到SSL模块

python安装完毕后,提示找不到ssl模块:


 
  1. [root@localhost ~]# python2.7.5

  2. Python 2.7.5 (default, Jun 3 2013, 11:08:43)

  3. [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2

  4. Type "help", "copyright", "credits" or "license" for more information.

  5. >>> import ssl

  6. Traceback (most recent call last):

  7. File "<stdin>", line 1, in <module>

  8. File "/usr/local/python27/lib/python2.7/ssl.py", line 60, in <module>

  9. import _ssl # if we can't import it, let the error propagate

  10. ImportError: No module named _ssl

  11. >>>

 重新编译python(去掉最后4行的注释)


 
  1. #修改Setup文件

  2. vi /root/Python-3.6.5/Modules/Setup.dist

  3. #修改结果如下:

  4. # Socket module helper for socket(2)

  5. _socket socketmodule.c timemodule.c

  6.  
  7. # Socket module helper for SSL support; you must comment out the other

  8. # socket line above, and possibly edit the SSL variable:

  9. SSL=/usr/local/ssl

  10. _ssl _ssl.c \

  11. -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \

  12. -L$(SSL)/lib -lssl -lcrypto

编译安装


 
  1. ./configure --prefix=/usr/local/python

  2. make

  3. make install

测试,已可正常使用。


 
  1. [root@localhost ~]# python

  2. Python 3.6.4 (default, Jun 3 2013, 14:56:13)

  3. [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2

  4. Type "help", "copyright", "credits" or "license" for more information.

  5. >>> import ssl

  6.  
    原文作者:robert_xiaoqi
    原文地址: https://blog.csdn.net/qq_41714057/article/details/81326858
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞