CryptographyDeprecationWarning:Python 2 不再受 Python 核心团队支持

CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team

我收到这个错误:

/System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/OpenSSL/crypto.py:14: CryptographyDeprecationWarning: Python 2 is no longer supported by the Python core team. Support for it is now deprecated in cryptography, and will be removed in the next release. from cryptography import utils, x509

我已尝试更新加密模块和 python。这个问题的解决方案是什么?

macOS Monterey 作为 Python 2.7.18 发布 /usr/bin/python 以及一组默认包。此 Python 是作为与遗留软件兼容的最终回退而提供的。执行此 Apple 提供的 Python 时,您将看到以下初始消息:

WARNING: Python 2.7 is not recommended. 
This version is included in macOS for compatibility with legacy software. 
Future versions of macOS will not include Python 2.7. 
Instead, it is recommended that you transition to using 'python3' from within Terminal.

由于他们正在运送一套他们已经运送多年的包裹,其中包括 cryptography,它也弃用了 Python 2 支持,并开始发出关于在版本 3.3 中放弃支持的警告。 Apple 发布了 3.3.2 版,这是 cryptography 支持 Python 2.

的最终版本

唯一真正解决这个问题的方法是停止使用 Python 2. 您可以从 python.org 安装更新的 Python,使用 pyenv 或 conda 等工具,或使用 Apple 的 Python3,但是需要迁移。当然,明年 macOS 13 发布时,Apple 可能会放弃安装 py2。

编辑:Apple 实际上在 macOS 12.3 中删除了 Python 2。