Python error: “libssl.so.1.1: cannot open shared object file: No such file or directory”

My website went down a couple of days ago. Apparently Dreamhost had moved my VPS which broke my custom Python installation’s reference to the system ssl module. Reinstalling my Python version (and re-creating my site’s virtual environment) fixed it.

My website went down a couple of days ago. When I dug into it, I found this error:

libssl.so.1.1: cannot open shared object file: No such file or directory

Too long; didn’t read

It seems that Dreamhost had moved my Virtual Private Server (VPS), and I needed to reinstall my custom Python version and re-create my site’s virtual environment.

The whole story

I was alerted to the problem from Google Search Console emails saying that it had detected pages returning 5xx errors. Sure enough, every page was returning a 503.

My website runs on a Dreamhost VPS running Ubuntu 22.04 (at the time of this problem, at least). It’s a Django site unning with Gunicorn behind a reverse proxy. The 503 is the proxy saying something is wrong with my service.

The Gunicorn service was down

I ssh'ed into the server. systemctl --user showed my gunicorn service loaded but failed. systemctl --user status orangegnome indicated three things

  1. orangegnome.service: Start request repeated too quickly.
  2. orangegnome.service: Failed with result 'exit-code'.
  3. Failed to start Gunicorn instance to serve application.

Because the site won’t run

Attempting to run my website through the Django runserver management command resulted in this error:

libssl.so.1.1: cannot open shared object file: No such file or directory

The stack trace showed an import _ssl line in a python package as where the error was happening.

And also pip is broken??

Running pip install -r requirements.txt to reinstall packages resulted in these odd warnings:
WARNING: Disabling truststore since ssl support is missing
WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.

Entering the Python interactive shell and executing import _ssl resulted in the same error as the website:

>>> import _ssl
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: libssl.so.1.1: cannot open shared object file: No such file or directory

But the system Python seems okay

By sheer luck, I tried the same with the system Python. My previous work had been with my site’s virtual environment activated. To my surprise, import _ssl worked with the system Python interactive shell.

Reinstalling Python (and re-creating the website virtual environment) fixed it

I was on verge of submitting a support ticket to Dreamhost when I checked my notifications in the panel and saw that Dreamhost had moved my VPS. Searching the libssl error had revealed some things around Python installation, so I thought that maybe a re-install of my Python version and a new virtual environment for my website would do it. And it did! I suppose when Python is installed, it creates the references to the system dependencies, and if they move or change then the reference is broken.