Programming Languages Bug Report

pyenv Python has no module named _ssl or _lzma: missing build dependencies

pyenv install finished, but pip could not reach PyPI and pandas warned about lzma. The interpreter had been built without OpenSSL and xz headers, and pyenv only warns. Build deps per OS, rebuild, and a one-line verification.

Marcus Lindqvist Marcus Lindqvist @marcuslindqvist · November 23, 2026 · 8 min read · 115 Views
606-pyenv-install-missing-ssl-lzma-build-deps

We moved a data team's nightly jobs from a hand-maintained server to fresh Ubuntu 24.04 build agents. The provisioning script installed pyenv, built the Python version the jobs pin in .python-version, created a virtual environment and ran pip install -r requirements.txt. The first run failed immediately:

WARNING: pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/pandas/
ERROR: Could not find a version that satisfies the requirement pandas==2.2.3 (from versions: none)

Copying the wheels in manually got the jobs a step further, then one job that reads .xz exports from a vendor died:

  File "/home/ci/.pyenv/versions/3.12.8/lib/python3.12/lzma.py", line 27, in <module>
    from _lzma import *
ModuleNotFoundError: No module named '_lzma'

Reproducing it

On a minimal Ubuntu 24.04 machine with only git, curl and build-essential installed:

curl -fsSL https://pyenv.run | bash        # or a git clone of pyenv
pyenv install 3.12.8
pyenv shell 3.12.8
python -c "import ssl"

The last command raises ModuleNotFoundError: No module named '_ssl' every time.

What we ruled out

  • A proxy or certificate problem. The error said the module was missing, not that a certificate failed to verify. curl https://pypi.org/simple/ worked from the same agent.

  • A broken pip. python -m ensurepip succeeded, but pip itself needs ssl to talk to PyPI, so reinstalling pip changed nothing.

  • A bad Python release. The same 3.12.8 build worked on the old server, and the system /usr/bin/python3 (3.12 from Ubuntu) imported ssl and lzma fine.

The build log told the story. We reran with verbose output:

pyenv install -v 3.12.8 2>&1 | tee build.log
grep -iE "ssl|lzma|_ctypes|readline|sqlite|could not build|missing" build.log | tail -20

Near the end CPython's build listed what it skipped:

The necessary bits to build these optional modules were not found:
_bz2                  _ctypes               _curses
_curses_panel         _dbm                  _gdbm
_lzma                 _ssl                  _tkinter
_uuid                 readline
To find the necessary bits, look in configure.ac and config.log.

Root cause

CPython builds many standard library modules as optional C extensions. If the development headers for a library (OpenSSL, xz/liblzma, bzip2, libffi, readline and others) are not installed when configure runs, the build skips that module and still completes successfully. pyenv reports this as a warning and exits 0, so our provisioning script carried on with an interpreter missing a dozen modules. The old server had the -dev packages installed years ago by someone who no longer remembered doing it.

What is happening under the hood

Modules like ssl, lzma, bz2, ctypes, sqlite3, readline and uuid are thin Python wrappers over C extensions (_ssl, _lzma, _bz2, _ctypes, _sqlite3, readline, _uuid). Those extensions link against system libraries. At compile time they need the headers and the shared library; at run time only the shared library. A runtime-only package (for example libssl3t64 on Ubuntu 24.04) is not enough to build.

Since Python 3.10, the ssl module requires OpenSSL 1.1.1 or newer (PEP 644). Very old distributions that ship only OpenSSL 1.0 produce the same missing-_ssl symptom even with headers installed.

pyenv uses python-build, which downloads the source tarball, runs configure and make, and prints warnings such as:

WARNING: The Python ssl extension was not compiled. Missing the OpenSSL lib?
WARNING: The Python lzma extension was not compiled. Missing the lzma lib?

Those warnings scroll past easily in CI logs. A virtual environment created from that interpreter inherits the same gaps, because a venv shares the base interpreter's compiled modules.

Environment

Component

Version / value

OS

Ubuntu 24.04 LTS (fresh cloud image)

pyenv

2.5.x

Python

3.12.8 built from source by pyenv

Present packages

git, curl, build-essential only

Missing

libssl-dev, liblzma-dev, libbz2-dev, libffi-dev, libreadline-dev, libsqlite3-dev, tk-dev, uuid-dev and others

Minimal reproduction

python - <<'PY'
import importlib
for name in ["ssl", "lzma", "bz2", "ctypes", "sqlite3", "readline", "uuid", "zlib", "tkinter"]:
    try:
        importlib.import_module(name)
        print(f"ok      {name}")
    except Exception as exc:
        print(f"MISSING {name}: {exc}")
PY

On the broken interpreter this printed MISSING for seven modules.

Who is affected

Anyone compiling Python from source: pyenv, asdf and mise when they build rather than download, plain ./configure && make in Dockerfiles, and some CI images. Prebuilt interpreters (distribution packages, the python.org macOS installer, uv python install, or mise configured to use precompiled builds) are not affected because they ship with these modules already compiled.

The fix

1. Install the build dependencies listed in the pyenv wiki for the OS. On Ubuntu and Debian:

sudo apt-get update
sudo apt-get install -y make build-essential libssl-dev zlib1g-dev \
  libbz2-dev libreadline-dev libsqlite3-dev curl git \
  libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev \
  libffi-dev liblzma-dev uuid-dev

On Fedora, RHEL and derivatives:

sudo dnf install -y make gcc patch zlib-devel bzip2 bzip2-devel \
  readline-devel sqlite sqlite-devel openssl-devel tk-devel \
  libffi-devel xz-devel libuuid-devel gdbm-libs libnsl2

On macOS with Homebrew (Xcode Command Line Tools installed first with xcode-select --install):

brew install openssl readline sqlite3 xz tcl-tk zlib

python-build detects Homebrew's OpenSSL and readline by itself on macOS; you rarely need to set CFLAGS or LDFLAGS by hand any more.

2. Rebuild the interpreter. A rebuild is required; installing packages afterwards does not add modules to an existing build.

pyenv uninstall -f 3.12.8
pyenv install 3.12.8

3. Recreate every virtual environment created from the broken build. Their pyvenv.cfg points at the same base, so after the rebuild they usually work, but any wheels compiled against the broken interpreter should be rebuilt. We deleted and recreated them:

rm -rf .venv
python -m venv .venv
. .venv/bin/activate
pip install -r requirements.txt

4. Fail the build on missing modules. In the provisioning script, right after pyenv install:

pyenv exec python -c "import ssl, lzma, bz2, ctypes, sqlite3, readline, uuid, zlib; print(ssl.OPENSSL_VERSION)"

If any import fails, the script exits non-zero and the agent never joins the pool.

Alternatives and trade-offs

  • Use a prebuilt Python. uv python install 3.12 or mise with precompiled Python downloads standalone builds with every module included. No compiler needed, much faster on CI. Trade-off: different build flags from distro Python, and you depend on that project's build cadence for security releases.

  • Use the distribution's Python. On Ubuntu 24.04 that is 3.12. Fine if the pinned version matches; you get security updates through apt. You cannot pick an arbitrary patch release.

  • Official python Docker images. Built from source with all dependencies, maintained upstream. A good choice if the jobs can run in containers.

  • Set PYTHON_CONFIGURE_OPTS. Useful for things like --enable-shared (needed by some embedding tools), but it does not fix missing headers.

How to test the fix

pyenv exec python -c "import ssl; print(ssl.OPENSSL_VERSION)"
pyenv exec python -c "import lzma; lzma.compress(b'test'); print('lzma ok')"
pyenv exec python -m pip download --no-deps -d /tmp/pipcheck six

Expected output: an OpenSSL 3.x version string, lzma ok, and pip saving a wheel without TLS warnings.

Confirming in production

After reprovisioning the agents, the nightly jobs ran end to end. We grepped the job logs for the strings that started this:

grep -E "ssl module in Python is not available|No module named '_(ssl|lzma)'" job-*.log | wc -l

The count was zero for every night since, and the .xz import job processed its vendor files on the first night.

Regression guard

  • The import check above runs in the provisioning script and in the base image build. A build without _ssl or _lzma can no longer be published.

  • The dependency list lives in one script used by both the agent image and developer containers, so they cannot drift.

  • python -m test.test_ssl -q and python -m test.test_lzma -q are cheap extra checks we run weekly on the base image to catch library changes.

Security implications

An interpreter without ssl cannot verify TLS at all, and the fastest workaround people reach for is --trusted-host or plain HTTP indexes. That would let anyone on the path tamper with packages. We explicitly forbade those flags in the job configuration and kept HTTPS-only indexes. Linking against the distribution's maintained OpenSSL (libssl-dev) also means security patches to OpenSSL reach the interpreter through normal apt upgrades, while the Python patch version still needs a deliberate rebuild.

Prevention checklist

  • Install the pyenv wiki's build dependencies before the first pyenv install on any new OS image.

  • Treat python-build warnings as errors in automation.

  • Verify ssl, lzma, bz2, ctypes, sqlite3 and zlib import after every build.

  • Prefer prebuilt interpreters on CI when you do not need custom flags.

  • Recreate virtual environments after rebuilding their base Python.

References

Add a label

#python #openssl #macos #ubuntu #pyenv #xz
Written by
Marcus Lindqvist @marcuslindqvist

I have spent most of the last decade on mobile teams, first native iOS, then React Native and Flutter for companies that needed one team to ship to both stores. The work I enjoy most is the unglamorous part between "it runs on my phone" and "it is live for a million users": code signing, release builds, store review, crash triage and background behaviour that differs on every Android vendor. Most of the bugs I write about here cost a release day. Each post shows the exact error, what we ruled out, the fix and how we proved it in the next build, so you can get your own release out the door sooner.

Advertisement

Comments

0

No comments yet. Be the first to comment!

Sign In to post a comment.