错误:pip is configured with locations that require TLS/SSL, however the ssl module in Python is not...

关于在使用 pip 出现找不到 ssl 模块的问题。

在网上有很多人说在编译的时候需要添加 --with-ssl ,但是在添加之后确实也会出现警告configure: WARNING: unrecognized options: --with-ssl 又有人说这个选项已经不支持了,没有作用了。但是我在3.6.8版本时候的时候,虽然也是出现了警告,但是当我继续编译安装之后,引用ssl模块是可行的。

[root@root83 Python-3.6.8]# ./configure --prefix=/usr/local/Python3.6/ --enable-optimizations --enable-loadable-sqlite-extensions --with-ssl
...
configure: WARNING: unrecognized options: --with-ssl  #会出现--with-ssl警告
...
[root@root83 Python-3.6.8]# make && make install
...
(cd /usr/local/Python3.6/bin; ln -s pyvenv-3.6 pyvenv)
if test "x" != "x" ; then \
    rm -f /usr/local/Python3.6/bin/python3-32; \
    (cd /usr/local/Python3.6/bin; ln -s python3.6-32 python3-32) \
fi
rm -f /usr/local/Python3.6/share/man/man1/python3.1
(cd /usr/local/Python3.6/share/man/man1; ln -s python3.6.1 python3.1)
if test "xupgrade" != "xno"  ; then \
    case upgrade in \
        upgrade) ensurepip="--upgrade" ;; \
        install|*) ensurepip="" ;; \
    esac; \
     ./python -E -m ensurepip \
        $ensurepip --root=/ ; \
fi
Looking in links: /tmp/tmpuzdf0qz1
Requirement already up-to-date: setuptools in /usr/local/Python3.6/lib/python3.6/site-packages (40.6.2)
Requirement already up-to-date: pip in /usr/local/Python3.6/lib/python3.6/site-packages (18.1)
# 以上是编译安装完成
(py3) [root@root83 Python-3.6.8]# python3.6 
Python 3.6.8 (default, Jun 10 2019, 23:48:04) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-36)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> 
# 以上是成功引用模块

如果不想使用 --with-ssl 选项,可以参考https://chowyi.com/%E6%BA%90%E7%A0%81%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85Python3%E5%8F%8A%E9%97%AE%E9%A2%98%E8%A7%A3%E5%86%B3/ 修改Python源码 setup.py 文件,更改引用ssl模块的路径。
CentOS 7.6 系统的模块一般都是安装在 /usr/include/ 目录下。

ython 源码 引用 ssl 模块的路径可以改为:

# Detect SSL support for the socket module (via _ssl)
        search_for_ssl_incs_in = [
                              '/usr/local/ssl/include',
                              '/usr/include/openssl', # 添加此行,否则可能会报错找不到 rsa.h 文件
                              '/usr/contrib/ssl/include/'

修改Python3.6.1/Module/Setup.dist文件:

# line: 207
# 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

把上面的四行注释放开,然后再执行:

[root@root83 Python-3.6.8]# ./configure --prefix=/usr/local/Python3.6/ --enable-optimizations --enable-loadable-sqlite-extensions 
[root@root83 Python-3.6.8]# make # 注意make之后的日志 ssl 模块是否加载成功。
[root@root83 Python-3.6.8]# make install

方法参考自:http://stackoverflow.com/questions/5937337/building-python-with-ssl-support-in-non-standard-location
http://stackoverflow.com/questions/5128845/importerror-no-module-named-ssl

注意:修改 Python 源码的方法可能会造成不必要的麻烦。

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 家园建造与种植资料分类汇总标签(空格分隔): 家园建造 种植技术 原文链接(自带目录导航):家园建造与种植资料分类...
    中道心阅读 1,463评论 0 3
  • 【Aipm引导页】 https://58976235.wodemo.net/down/20170514/44034...
    Mr_洛寒阅读 2,692评论 3 5
  • 100+ 经典技术书籍,涵盖:计算机系统与网络、系统架构、算法与数据结构、前端开发、后端开发、移动开发、数据库、测...
    玥玥籽阅读 1,523评论 0 2
  • (开始) (标题)iApc(/标题)(链接)https://duming666.wodemo.net/down/2...
    独名阅读 1,640评论 1 3
  • ### 前言 #### 成为一名优秀的Android开发,需要一份完备的[知识体系](https://github...
    JsonChao阅读 2,368评论 0 11