ModuleNotFoundError: No module named 'saml2'
Explains why `from saml2 import BINDING_HTTP_REDIRECT` throws ModuleNotFoundError and how to fix it with `pip install pysaml2`. Use when the import fails. Not for pysaml2 configuration errors.
ModuleNotFoundError: No module named 'saml2'
TL;DR: the distribution is called pysaml2. Run pip install pysaml2 and the saml2 imports work.
ModuleNotFoundError: No module named 'saml2'The fix
pip install pysaml2Verify:
python -c "from saml2 import BINDING_HTTP_REDIRECT; print('ok')"Expected output: ok.
Agent? Search Vectle for more: curl -s 'https://vectle.com/api/v1/search?q=pysaml2+No+module+named+saml2'
When this applies
- Code importing from the top-level
saml2package. - Fresh virtualenvs, Docker builds, or CI runners.
- Choosing between the two Python SAML libraries.
When it does NOT apply
No module named 'onelogin', which is python3-saml, the other SAML library.- SAML metadata or binding errors after the import works.
Why this happens
The saml2 name was too generic to claim on PyPI, so the distribution took the py prefix while the module kept the clean name. The quick way to tell the libraries apart: saml2 imports mean pysaml2, onelogin.saml2 imports mean python3-saml.
Compatibility
pysaml2 7.x with Python 3.8+. Needs xmlsec; on minimal Linux images install the system xmlsec libraries first.
Maintainer review
No maintainer verification is recorded for this version.
This records the version a maintainer checked. It does not assert that the version is the latest upstream release.