centos6.10下安装支持ssl的python3

安装及排错过程:

一, 安装python3.7

          安装依赖包

          yum -y install zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel libffi-devel

           下载  https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tgz

            解压 tar -zxvf Python-3.7.0.tgz -C /usr/local

            cd /usr/local

            mkdir python3

            cd Python-3.7.0

            ./configure --prefix=/usr/local/python3

            make

            make install         

           建立软链接

           ln -s /usr/local/python3/bin/python3.7 /usr/bin/python3

           ln -s /usr/local/python3/bin/pip3.7 /usr/bin/pip3

           但是当在python3中导入opencv库时出错

           python3
           import cv2
           Traceback (most recent call last):
           File "", line 1, in
           ModuleNotFoundError: No module named 'cv2'

           网搜需要pip3 install opencv-python

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

    试了一下在python3中import ssl确实失败,网搜有效方案如下(./configue 加上--with-ssl是无效的):

          cd Python-3.7.0

          make clean  #如果已经和我一样编译过一次,建议先执行此步骤,否则可省略。

         ./configure prefix=/usr/local/python3

        修改./Modules/Setup文件(将如下五行的注释去掉):

         _socket socketmodule.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

         添加动态链接库cd /etc/ld.so.conf.d vi ssl.conf /usr/local/ssl/lib

         cd /usr/local/Python-3.7.0

         make   这时会报错说ssl版本太低  error "libssl is too old and does not support X509_VERIFY_PARAM_set1_host()"

         升级步骤为:下载源码包--编译安装---备份旧的openssl文件---设置新的软链接---测试。
         wget http://www.openssl.org/source/openssl-1.0.2g.tar.gz
         tar -zxvf openssl-1.0.2g.tar.gz
         cd openssl-1.0.2g
        ./config shared zlib
         make && make install
         #修改历史的OpenSSL文件设置备份
         mv /usr/bin/openssl /usr/bin/openssl.old
         #设置软连接使其使用新的OpenSSL版本 刚刚安装的OpenSSL默认安装在/usr/local/ssl
         ln -s /usr/local/ssl/bin/openssl /usr/bin/openssl
         我们再来看看OpenSSL版本信息
         openssl version

          这样再重新make && make install 能安装成功

          再在python3下import ssl成功, exit()退出

           再用pip3 install opencv-python成功。 并提示pip3 install --upgrade pip升级pip3为19.XX版本

          python3 下import cv2成功

参考文章:

https://blog.csdn.net/Pc620/article/details/86163275

https://blog.csdn.net/qq_36617639/article/details/88939873

https://blog.51cto.com/12476193/2304878

 

你可能感兴趣的:(linux)