pip or Python crashes on X509_V_FLAG_CB_ISSUER_CHECK at import
Your error
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'2 more lines it can showFix it fast
Most common cause, 1 of 2pyOpenSSL in the environment is too old for its cryptography
Upgrade pyOpenSSL in that environment.
python -m pip install --upgrade pyopenssl
python -m pip checkShort answer
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK' means an old pyOpenSSL is being imported with a newer cryptography that no longer exposes that constant. In a virtual environment, upgrade pyOpenSSL; 26.4 accepts only cryptography 49 to 50. On a distro Python, where apt owns pyOpenSSL, install your packages in a venv instead.
Which cause do you have?
Print where cryptography loads from and set it beside the OpenSSL/crypto.py path in the traceback. Both inside one virtual environment points to cause 1; OpenSSL under /usr/lib/python3/dist-packages, the folder apt manages, with cryptography under /usr/local points to cause 2.
python3 -c "import cryptography; print(cryptography.__version__, cryptography.__file__)"Then find the line you see in this list and open its fix:
- 1pyOpenSSL in the environment is too old for its cryptography
OpenSSL/crypto.py sits in the same site-packages as cryptography, and pip show reports pyOpenSSL around 20 or 21 next to a much newer cryptography - 2apt's pyOpenSSL meets a cryptography installed later with pip
The traceback runs through /usr/lib/python3/dist-packages/OpenSSL and, on Ubuntu 20.04, through /usr/share/python-wheels/urllib3, so even pip itself fails
What does the error look like?
AttributeError: module 'lib' has no attribute 'X509_V_FLAG_CB_ISSUER_CHECK'CB_ISSUER_CHECK = _lib.X509_V_FLAG_CB_ISSUER_CHECKFile "/usr/lib/python3/dist-packages/OpenSSL/crypto.py", line 1573, in X509StoreFlags
Cause 1 of 2
pyOpenSSL in the environment is too old for its cryptography
You seeOpenSSL/crypto.py sits in the same site-packages as cryptography, and pip show reports pyOpenSSL around 20 or 21 next to a much newer cryptography
Check
pyOpenSSL reads X509_V_FLAG_CB_ISSUER_CHECK from cryptography's bindings when OpenSSL.crypto is imported, and newer cryptography builds dropped it. In the pyOpenSSL tracker, the maintainers trace this exact AttributeError to mixing versions and advise moving to the latest pyOpenSSL.
python -m pip show pyopenssl cryptography | grep -E "^(Name|Version)"Fix
Upgrade pyOpenSSL in that environment. Since 22.1.0 every pyOpenSSL release pins a matching range of cryptography, so pip pulls a compatible pair. Pinning cryptography back also stops the error, but it leaves you without security fixes.
python -m pip install --upgrade pyopenssl
python -m pip checkVerify
OpenSSL imports cleanly and prints its version.
python -c "import OpenSSL; print(OpenSSL.__version__)"Confirmed by github.com
Cause 2 of 2
apt's pyOpenSSL meets a cryptography installed later with pip
You seeThe traceback runs through /usr/lib/python3/dist-packages/OpenSSL and, on Ubuntu 20.04, through /usr/share/python-wheels/urllib3, so even pip itself fails
Check
The distribution's own software depends on the python3-openssl and python3-cryptography versions apt installed. Running sudo pip install --upgrade cryptography, or installing anything that pulls it in, replaces only one half. cryptography's maintainers explain that an outdated pip with an outdated urllib3 then loads the old pyOpenSSL automatically, which is why pip breaks too.
ls -d /usr/local/lib/python3*/dist-packages/cryptography*Fix
Stop mixing sources. Both the pip and cryptography maintainers point to a virtual environment, which keeps the packages you install, and a current pip, apart from the ones apt manages.
python3 -m venv ~/venvs/app
~/venvs/app/bin/python -m pip install --upgrade pip
~/venvs/app/bin/python -m pip install -r requirements.txtVerify
Commands run through the venv's python finish, and the traceback no longer mentions dist-packages/OpenSSL.
~/venvs/app/bin/python -m pip --versionConfirmed by github.com
How do I stop it coming back?
- Never run sudo pip install on a distribution's Python; apt and pip each assume they own every package there.
- Keep pyopenssl in the same lock file as cryptography so the pair always moves together.
- Run python -m pip check in CI after installs; it exits non-zero when an installed package's dependencies are not compatible.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.