解决 Python 3.8+ 遇到的 OpenSSL 版本不兼容的问题
在安装 Python3.8 时可能会遇到与系统自带 OpenSSL 版本不兼容的问题。Python3.8 需要的 OpenSSL 版本为 1.0.2
或 1.1.x
。如果系统中默认的 OpenSSL 版本低于需求(通常是 OpenSSL 1.0.1
),会导致如下错误:
Could not build the ssl module!
Python requires an OpenSSL 1.0.2 or 1.1 compatible libssl with X509_VERIFY_PARAM_set1_host().
查询当前 OpenSSL 版本
openssl version
如果版本低于 Python3.8 的需求,就需要升级 OpenSSL。
升级 OpenSSL 步骤
1. 下载新版 OpenSSL
前往 OpenSSL 官方网站 下载需要的版本。以 OpenSSL 1.1.1n 为例:
wget https://www.openssl.org/source/old/1.1.1/openssl-1.1.1n.tar.gz
2. 解压安装包
tar -xvzf openssl-1.1.1n.tar.gz
3. 编译安装
cd openssl-1.1.1n
./config --prefix=/usr/local/openssl no-zlib # 新版openssl将安装在/usr/local/openssl目录下
make
make install
新版 OpenSSL 将安装在 /usr/local/openssl
目录下。
4. 备份原系统 OpenSSL
升级前,备份原系统自带的低版本 OpenSSL 以便回滚:
mv /usr/bin/openssl /usr/bin/openssl_bak
mv /usr/include/openssl/ /usr/include/openssl_bak
5. 配置新版 OpenSSL
为新版 OpenSSL 创建软连接:
# 将安装好的openssl的openssl命令软连到/usr/bin/openssl
ln -s /usr/local/openssl/include/openssl /usr/include/openssl
# 软链到升级后的libssl.so
ln -s /usr/local/openssl/lib/libssl.so.1.1 /usr/local/lib64/libssl.so
# 将安装好的openssl命令软连到/usr/bin/openssl
ln -s /usr/local/openssl/bin/openssl /usr/bin/openssl
6. 修改系统配置
# 写入openssl库文件的搜索路径
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf # 需要root权限
# 使修改后的/etc/ld.so.conf生效
ldconfig -v
7. 验证安装结果
openssl version
输出应类似于:
OpenSSL 1.1.1n 15 Mar 2022
8. 追加环境变量
vim ~/.bashrc
export LDFLAGS="-L/usr/local/openssl/lib"
export CPPFLAGS="-I/usr/local/openssl/include"
export PKG_CONFIG_PATH="/usr/local/openssl/lib/pkgconfig"
source ~/.bashrc
升级完新版本的 OpenSSL 之后,需要对 Pyhton 3.8 进行重新编译并更新软连接才能继续使用 Python 3.8。
发表评论
文章归档
文章日历
2025 年 07 月 | ||||||
---|---|---|---|---|---|---|
日 | 一 | 二 | 三 | 四 | 五 | 六 |
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
文章标签
- Linux
- Go
- Yii
- 新浪
- CentOS
- PHP
- Git
- WSL
- Composer
- Mac
- 入职
- Bootstrap
- pyenv
- UCenter
- 厦门
- 出差
- 长沙
- 湖南卫视
- 微博
- Tengine
- YUI
- 泰国
- pecl
- 优化
- GitLab
- 迁移
- rootless
- 年会
- 生日
- Tengin
- RedHat
- Sphinx
- cygwin
- Windows
- Tmux
- Zsh
- 升级
- MySQL
- sql_mode
- Shadowsockets
- 面向对象
- HTTP
- 状态码
- grep
- unoconv
- PPT
- Nginx
- htpasswd
- golang
最新评论
-
崔亮 于 19-05-23 评论了Tengine 2.2.2 配置 http2 协议出现的坑
-
王媛 于 19-01-31 评论了Yii China 是官方唯一认可的中文社区
-
三杯蛙 于 19-01-24 评论了Go 语言中 json 的操作以及常见问题
-
三杯蛙 于 19-01-24 评论了新浪赴泰国曼谷和芭提雅团建
-
巡洋舰 于 18-09-05 评论了CentOS 安装 PHP7
-
小不点 于 11-03-02 评论了WordPress 如何控制每页显示的条数
-
白领厕工 于 10-12-22 评论了关于 phpMyAdmin 免输入用户名和密码,直接进入管理界面
-
清晨的欣赏 于 10-08-04 评论了PHP 5.4 的新特性
-
易赛官网 于 10-07-27 评论了PHP 5.4 的新特性
-
文秘之家 于 10-07-17 评论了PHP 5.4 的新特性
常用工具
- 时间戳转换
- URL ENCODE/DECODE
- JSON
- 正则测试
共 0 条评论