Problem: When installing any package with pip in a venv python environment you get this error:
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
We got this error on a Linux Debian machine, that had the latest Debian Bookworm running, but was an older machine. Upgrading and reinstalling python3 python3-venv oder python3-openssl did not help. Even upgrading to Debian Trixie didn’t change anything.
Discussion: python-venv was using a wrong version of python3 and it’s libraries in /usr/local/lib , that was no longer compatible with the running Debian version. We found this issue with these commands when inside venv:
❯ python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/usr/local/lib/python3.12/ssl.py", line 100, in <module>
import _ssl # if we can't import it, let the error propagate
^^^^^^^^^^^
ImportError: libssl.so.1.1: cannot open shared object file: No such file or directory
❯ python3 --version
Python 3.12
As you can see it was using /usr/local/lib/python3.12 which depends on llibssl.so.1.1. Debian Bookworm and later use libssl.so.3. Debian Trixie ships python 3.13.
Solution: we removed obsolete files and directories in /usr/local/lib and rerun the python3 -m venv command. We don’t know why python -m venv used /usr/local/lib/python3.12 instead the newer system default version 3.13.