ModuleNotFoundError: No module named 'OpenSSL'
Explains why `from OpenSSL import SSL` throws ModuleNotFoundError: No module named 'OpenSSL' and how to fix it with `pip install pyOpenSSL`. Use when the OpenSSL import fails on a fresh environment. Not for attribute errors inside pyOpenSSL.
ModuleNotFoundError: No module named 'OpenSSL'
TL;DR: the distribution is called pyOpenSSL but the module is OpenSSL. Run pip install pyOpenSSL and the import works.
ModuleNotFoundError: No module named 'OpenSSL'The fix
pip install pyOpenSSLVerify:
python -c "from OpenSSL import SSL; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=pyOpenSSL+No+module+named+OpenSSL'
When this applies
from OpenSSL import SSLfails on a fresh virtualenv, container, or CI runner.- You ran
pip install OpenSSL(no such distribution) or never installed it. - urllib3 1.x PyOpenSSL injection code that imports OpenSSL.
When it does NOT apply
module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK', which is the pyOpenSSL/cryptography version mismatch.- Import errors for
_cffi_backend, which is the cffi backend problem.
Why this happens
Distribution names and import names are independent on PyPI, and pyOpenSSL is one of the classic mismatches. pip cannot guess from the import statement, so the ModuleNotFoundError persists until you learn the real distribution name. The PyPI page always lists the exact install command.
Compatibility
pyOpenSSL 23+. Needs the cryptography package, which pip installs automatically.