I am trying to install packages using pip, but I keep getting a warning that says: "pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available." This prevents me from downloading any libraries. I have OpenSSL installed on my system, so I'm not sure why Python can't find it. Is this an issue with my environment variables, a missing dependency during the Python build process, or do I need to reinstall Python entirely to fix the SSL configuration?
3 answers
This error usually means that your Python installation was compiled or installed without linking to the necessary OpenSSL development headers.
-
On Ubuntu/Debian: You need to install the development files first. Run
sudo apt-get update && sudo apt-get install libssl-dev. If you built Python from source, you must re-run./configureandmake installafter installing this package. -
On Windows: This often happens if the OpenSSL DLLs (
libssl.dllandlibcrypto.dll) are missing from your PATH. Reinstalling Python and checking the box "Add Python to PATH" usually fixes this. Alternatively, if you use Anaconda, try runningconda install openssl. -
On macOS: If you used Homebrew, ensure your environment can see the brew-installed OpenSSL by adding it to your
.zshrcor.bash_profile:export PATH="/usr/local/opt/openssl/bin:$PATH".
I had this exact same problem on a CentOS server! It turns out Python 3.10 and above require OpenSSL 1.1.1 or newer. If your OS is older (like CentOS 7), the default OpenSSL is too old. I had to install openssl11-devel and then rebuild Python using the flag ./configure --with-openssl=/usr/include/openssl11. Has anyone else found a way to do this without recompiling the whole thing from source?
If you are seeing this inside a Virtual Environment, sometimes the environment gets corrupted. Try deleting the venv folder and creating a new one. It usually inherits the SSL capability from the global Python interpreter correctly the second time.
I agree with Maria. I actually ran into this exact issue last week while working on a Data Science project. The virtual environment wasn't picking up the updated OpenSSL libraries I had installed on my host machine. Deleting the venv and re-running python -m venv venv forced it to re-link the global binaries, including the fixed SSL module. It's a much faster fix than trying to manually patch the environment variables.
James, for users who don't want to compile from source, using a version manager like pyenv is a lifesaver. pyenv handles the dependencies for you. On many systems, you just need to run sudo apt install libssl-dev and then pyenv install 3.x.x. It automatically links the SSL headers during the installation process, which is a best practice in modern software development.