Python3 installation to resolve SSL issues

Source: Internet
Author: User

Installing Python3.6.4 1 installation of python3.6 may be used by the dependency
yum install openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc gcc-c++  openssl-devel
2 to the Python website find the download path, download with wget
wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgz
3 Unpacking the TGZ package
tar -xf Python-3.6.5.tgz
4 Entering the Python directory
cd /Python-3.6.5/
5 compile, install 5.1 hint the SSL module could not be found

After the Python installation is complete, you are prompted not to find the SSL module:

[[email protected] ~]# python2.7.5Python 2.7.5 (default, Jun 3 2013, 11:08:43) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import sslTraceback (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 propagateImportError: No module named _ssl>>>
5.2 Recompile Python (minus the last 4 lines of comments)
#修改Setup文件vi /root/Python-3.6.5/Modules/Setup.dist#修改结果如下:# 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
5.3 Compiling the installation
./configure --prefix=/usr/local/pythonmakemake install
5.4 Test, can be used normally.
[[email protected] ~]# pythonPython 3.6.4 (default, Jun 3 2013, 14:56:13) [GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>> import ssl>>>

Note: If you want to keep the old version, you do not need to do 6.72

6 renaming old versions of Python dependencies
ll /usr/bin | grep pythonmv /usr/bin/python /usr/bin/python2.7
7 Delete old soft link, create new soft link to latest Python
rm -rf /usr/bin/pythonln -s /usr/local/bin/python3.6 /usr/bin/pythonpython -V

Use the Yum command to error file "/usr/bin/yum", line except Keyboardinterrupt, E:
The problem occurs because:

Yum package management is written using python2.x, and after upgrading python2.x to python3.1.3, the problem occurs due to Python version syntax compatibility
Workaround:
Modify the Yum configuration file to point the Python version to the previous old version

# vi /usr/bin/yum#!/usr/bin/python2.7

Modify the Urlgrabber-ext-down file to change the Python version

# vi /usr/libexec/urlgrabber-ext-down#!/usr/bin/python2.7

Could not fetch URL https://pypi.python.org/simple/six/: There is a problem confirming the SSL Certificate:can ' t connect The to-HTTPS URL because the SSL module is not available. -Skipping

If you want to install PIP Download related documents
curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py

Perform

/usr/local/python/bin/python3 get-pip.py
Adding environment variables
vim ~/.bash_profile

Add the following parameter

export PATH=/usr/local/python/bin:$PATH

Save
SOURCE ~/.bash_profile

Test

Perform

[[email protected] ~]# python3Python 3.6.5 (default, Apr  1 2018, 20:41:34)[GCC 4.8.5 20150623 (Red Hat 4.8.5-16)] on linuxType "help", "copyright", "credits" or "license" for more information.>>>
Execute the script as follows:

Vim install_python.sh

#!/bin/bashecho "正在安装相关组件"yum install -y openssl-devel bzip2-devel expat-devel gdbm-devel readline-devel sqlite-devel gcc-c++ gcc openssl-develecho "下载安装包"wget https://www.python.org/ftp/python/3.6.5/Python-3.6.5.tgzecho "正在解压安装包"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.cSSL=/usr/local/ssl_ssl _ssl.c -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl -L$(SSL)/lib -lssl -lcryptoEOFecho "正在编译安装Python"./configure --prefix=/usr/local/python && make && make installcd /rootecho "删除安装包"rm -rf /root/Python-3.6.5.tgz && rm -rf /root/Python-3.6.5echo "正在添加环境变量"echo "export PATH=/usr/local/python/bin:$PATH">> ~/.bash_profilesource ~/.bash_profileecho "安装完成,请执行python3进行测试"

Python3 installation to resolve SSL issues

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.