Python是一种解释型、面向对象、动态数据类型的高级程序设计语言。

编译安装python3.7.1并支持ssl 模块

环境说明

环境:
  python 3.7.1
  centos 7.4

解决依赖关系

1
[root@localhost ~]# yum install -y openssl openssl-devel libffi-devel zlib*

编译安装python

1
2
3
4
5
[root@localhost ~]# wget -c 'https://www.python.org/ftp/python/3.7.1/Python-3.7.1.tar.xz'
[root@localhost ~]# tar -xf Python-3.7.1.tar.xz
[root@localhost ~]# cd Python-3.7.1
[root@localhost Python-3.7.1]# ./configure --prefix=/usr/local/python3.7 --with-ssl
[root@localhost Python-3.7.1]# make && make install

设置环境变量

1
2
3
4
5
[root@localhost ~]# cat /etc/profile.d/python37.sh
#!/bin/bash
python37="/usr/local/python3.7"
export PATH=$PATH:${python37}/bin
[root@localhost ~]# source /etc/profile.d/python37.sh

测试python

1
2
3
[root@localhost ~]# python3.7 --version
Python 3.7.1
[root@localhost ~]#

test_ssl_module

Question

如果不安装libffi-devel,在编译时会报下面的错误

1
2
3
4
File "/root/Python-3.7.0/Lib/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
make: *** [install] Error 1

如果不安装openssl,在使用ssl模块时会报错

1
2
3
4
5
6
7
8
9
10
11
12
13
pip is configured with locations that require TLS/SSL, however the ssl module in Python is
not available.Collecting douyin
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after conn
ection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/douyin/ Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after conn
ection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/douyin/ Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after conn
ection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/douyin/ Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after conn
ection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/douyin/ Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after conn
ection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/douyin/ Could not fetch URL https://pypi.org/simple/douyin/: There was a problem confirming the s
sl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/douyin/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping Could not find a version that satisfies the requirement douyin (from versions: )
No matching distribution found for douyin
pip is configured with locations that require TLS/SSL, however the ssl module in Python is
not available.Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl ce
rtificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping

1
2
3
...
You are using pip version 10.0.1, however version 18.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
1
[root@localhost ~]# python3.7 -m pip install --upgrade pip

本作品采用知识共享署名 2.5 中国大陆许可协议进行许可,欢迎转载,但转载请注明来自Jack Wang Blog,并保持转载后文章内容的完整。本人保留所有版权相关权利。
打赏
本文出自”Jack Wang Blog”:http://www.yfshare.vip/2018/11/04/Python升级/