Python3.10下cryptography安装异常:ModuleNotFoundError求助
解决ModuleNotFoundError: No module named 'cryptography.hazmat.backends.openssl.x509'
这个报错的核心原因是cryptography 3.4.8与Python 3.10兼容性不足,同时pyopenssl 21.0.0依赖的cryptography内部API在该旧版本中存在适配问题。以下是具体解决步骤:
先卸载现有冲突的包:
pip uninstall -y cryptography pyopenssl清理pip缓存,避免残留旧版本文件干扰:
pip cache purge重新安装兼容Python 3.10的版本组合:
由于pyopenssl 21.0.0要求cryptography版本≥3.2,我们直接安装符合Python 3.10要求的cryptography版本(建议≥3.5):pip install pyopenssl==21.0.0 cryptography>=3.5验证安装:
执行以下命令确认导入正常:from cryptography.hazmat.backends.openssl.x509 import _Certificate若没有报错,则问题解决。
如果仍有问题,检查是否在正确的Python虚拟环境中操作,或者尝试升级pyopenssl到更高版本(比如22.0.0+),它会自动适配兼容的cryptography版本。
内容的提问来源于stack exchange,提问作者Harshit Trivedi
相关产品推荐
相关产品推荐

