Software Development

How do I fix the "ModuleNotFoundError: No module named '_ssl'" error in my Python environment?

KI Asked by Kimberly Adams · 10-09-2025
0 upvotes 15,678 views 0 comments
The question

I am trying to run a script that requires secure connections, but I keep hitting an error saying the SSL module is not found. I’ve tried reinstalling Python, but the issue persists. Is this a problem with how OpenSSL is installed on my OS, or am I missing a specific build flag during the installation of my virtual environment? I'm currently on a Linux-based system.

3 answers

0
BA
Answered on 12-09-2025

This error usually occurs when Python is compiled from source without the necessary OpenSSL development headers present on the system. On Ubuntu or Debian, you need to run sudo apt-get install libssl-dev before you build Python. If you are using pyenv, you might need to point the compiler to your OpenSSL directory using environment variables like LDFLAGS and CPPFLAGS. Once the headers are installed, you must re-run the make and make install commands for your Python version so it can properly link the _ssl extension during the build process.

0
RI
Answered on 14-09-2025

I’ve installed the headers as suggested, but my virtual environment still seems to be pointing to the old system binary. Is there a way to verify the SSL path Python is using?

TH 16-09-2025

You can verify the linked path by running import ssl; print(ssl.OPENSSL_VERSION) in your Python shell. If it throws an error there, your binary wasn't linked at all. If it works, it will show the version. Often, simply deleting and recreating your virtual environment after installing libssl-dev on the host machine solves the mapping issue because the venv will then reference the newly updated system interpreter.

0
PA
Answered on 05-10-2025

Most of the time, this is just a missing libssl package on your OS. Install that, rebuild Python, and the error should vanish immediately.

KI 07-10-2025

Patricia is right. For macOS users encountering this, using brew install openssl and then providing the brew path to your installer is the standard fix for this exact same headache.

Share your thoughts

Your email address will not be published. Required fields are marked (*)

Professional Counselling Session

Still have questions?
Schedule a free counselling session

Our experts are ready to help you with any questions about courses, admissions, or career paths. Get personalized guidance from industry professionals.

Request a Call Back

Search Online

We Accept

We Accept

Follow Us

"PMI®", "PMBOK®", "PMP®", "CAPM®" and "PMI-ACP®" are registered marks of the Project Management Institute, Inc. | "CSM", "CST" are Registered Trade Marks of The Scrum Alliance, USA. | COBIT® is a trademark of ISACA® registered in the United States and other countries.

Book Free Session