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

I'm getting this error:

/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

I have tried updating the cryptography module and python. What is the solution to this problem?


Solution 1:

macOS Monterey ships /usr/bin/python as Python 2.7.18 along with a set of default packages. This Python is provided as a final fallback for compatibility with legacy software. When executing this Apple provided Python you will see the following initial message:

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.

Since they are shipping a set of packages that they have shipped for years, this includes cryptography, which also deprecated Python 2 support and began raising warnings about dropping support in version 3.3. Apple ships version 3.3.2, which is the final version of cryptography that supported Python 2.

The only true resolution to this is to stop using Python 2. You can install a newer Python from python.org, use tools like pyenv or conda, or use Apple's Python 3, but migration is required. And, of course, Apple will likely drop their py2 installation next year when macOS 13 is released.