You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Cryptography导入错误:undefined symbol: EVP_PKEY_get_id 求助

解决方法

1. 确认运行时链接的OpenSSL版本

先定位报错的.so文件依赖的OpenSSL库:

ldd /home/xy/Projects/cryptography/src/cryptography/hazmat/bindings/_rust.abi3.so

查看输出中libssl.so和libcrypto.so的指向——如果显示链接到libssl.so.1.1,就坐实了运行时加载旧版本的问题。

2. 强制用OpenSSL 3.0重新编译安装

先卸载现有依赖:

pip uninstall -y cryptography pyopenssl

设置环境变量指定OpenSSL 3.0的路径(适配你的系统路径):

export OPENSSL_ROOT_DIR=/usr
export OPENSSL_LIBRARIES=/usr/lib/x86-64-linux-gnu

重新安装修改后的库:

# 若cryptography是单独目录
pip install -e ./cryptography
# 若PyOpenSSL是单独目录
pip install -e ./pyopenssl
# 或者直接从项目根目录安装
pip install -e .

3. 调整库加载优先级

查看系统库的优先级:

ldconfig -p | grep libssl

如果libssl.so默认指向1.1版本,临时设置环境变量让Python优先加载3.0:

export LD_LIBRARY_PATH=/usr/lib/x86-64-linux-gnu:$LD_LIBRARY_PATH

测试运行项目,若有效,可将该环境变量添加到虚拟环境的activate脚本(如venv/bin/activate末尾),避免每次手动设置。

4. 验证Python与OpenSSL的绑定版本

检查当前Python使用的OpenSSL版本:

python -c "import ssl; print(ssl.OPENSSL_VERSION)"

若输出为1.x版本,说明Python本身编译时链接了旧版OpenSSL。可通过pyenv重新编译Python并指定OpenSSL路径:

pyenv install 3.10.12 --configure-openssl=/usr

5. 确认cryptography编译环境

安装完成后,验证cryptography实际使用的OpenSSL版本:

python -c "from cryptography.hazmat.backends.openssl.backend import backend; print(backend.openssl_version_text())"

若显示OpenSSL 3.0.2,说明编译正确,问题仅在运行时加载;若为旧版本,需重新检查环境变量设置并再次编译。

内容的提问来源于stack exchange,提问作者Dennis

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 11:26:14