pytorch / pytorch/audio

Packaging Regression in v2.9.0: torchaudio.load fails on non-shared Python builds

Open
#4,121 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.9k
Forks
799
Avg merge
58m
Merged PRs (30d)
3

Description

Summary

A packaging change in torch==2.9.0 and torchaudio==2.9.0 has introduced a regression that causes torchaudio.load() to fail on Linux systems where Python was not built with the --enable-shared flag. This is a very common configuration for developers who install Python from sources like the deadsnakes PPA on Ubuntu.

The failure occurs because the new torchcodec backend, now a default dependency, is linked against libpythonX.Y.so. When this shared library is not found in the systems standard paths, the program crashes with a RuntimeError. This breaks years of expected behavior where torchaudio worked reliably on these systems.

This violates the portability principles of the manylinux wheel standard.

Bug Description and Reproduction

Working Configuration:

  • torch==2.8.0+cpu
  • torchaudio==2.8.0+cpu
  • torchcodec is NOT installed.
  • torchaudio.load() works perfectly, correctly using the sox backend.

Failing Configuration:

  • torch==2.9.0+cpu
  • torchaudio==2.9.0+cpu
  • torchcodec==0.8.0 (installed as a dependency)
  • torchaudio.load() fails.

Error Log:

RuntimeError: Could not load libtorchcodec. ...
Diagnosis: The Root Cause

The error message is misleading. The true cause was diagnosed by running ldd on the .so files:

ldd /home/user/.local/lib/python3.10/site-packages/torchcodec/libtorchcodec_custom_ops7.so

This reveals the critical missing dependency:

libpython3.10.so.1.0 => not found

The torchcodec binary wheel for v0.8.0 is built in an environment that links it against libpython.so. This breaks compatibility with any Python installation that does not provide this shared library, which is common in non-conda, PPA-based, or manually compiled Python environments on Linux.

The older torchaudio==2.8.0 works because its compiled libraries do not link against libpython.so, respecting the manylinux standard and ensuring portability.

Steps to Reproduce
  1. Environment: Use Ubuntu 20.04 (or a derivative like Zorin OS 16.3) where the system Python is 3.8.
  2. Install Python 3.10 from the deadsnakes PPA: sudo add-apt-repository ppa:deadsnakes/ppa && sudo apt-get update && sudo apt-get install python3.10.
  3. Install the failing versions: pip install torch==2.9.0 torchaudio==2.9.0 torchcodec --index-url https://download.pytorch.org/whl/cpu.
  4. Execute a simple script: import torchaudio; torchaudio.load("some_audio.wav").
  5. Observe the RuntimeError.
  6. To confirm the fix, uninstall the packages and install the working versions: pip install torch==2.8.0 torchaudio==2.8.0 --index-url https://download.pytorch.org/whl/cpu. (Ensure torchcodec is uninstalled).
  7. Run the same script and observe that it succeeds.
Proposed Solution

This is a packaging regression that breaks a significant user workflow. The ideal solution is for the official torchcodec wheels to be built in a way that does not link against libpython.so, restoring the portability that is standard for the manylinux ecosystem.

Alternatively, if this is an intentional design choice, the failure should be more graceful, with a clear ImportError explaining that a Python installation with shared library support is now a requirement.

Ref:

  File "/home/usern/.local/lib/python3.10/site-packages/torchaudio/__init__.py", line 86, in load
    return load_with_torchcodec(
  File "/home/usern/.local/lib/python3.10/site-packages/torchaudio/_torchcodec.py", line 82, in load_with_torchcodec
    from torchcodec.decoders import AudioDecoder
  File "/home/usern/.local/lib/python3.10/site-packages/torchcodec/__init__.py", line 10, in <module>
    from . import decoders, samplers  # noqa
  File "/home/usern/.local/lib/python3.10/site-packages/torchcodec/decoders/__init__.py", line 7, in <module>
    from .._core import AudioStreamMetadata, VideoStreamMetadata
  File "/home/usern/.local/lib/python3.10/site-packages/torchcodec/_core/__init__.py", line 8, in <module>
    from ._metadata import (
  File "/home/usern/.local/lib/python3.10/site-packages/torchcodec/_core/_metadata.py", line 16, in <module>
    from torchcodec._core.ops import (
  File "/home/usern/.local/lib/python3.10/site-packages/torchcodec/_core/ops.py", line 84, in <module>
    load_torchcodec_shared_libraries()
  File "/home/usern/.local/lib/python3.10/site-packages/torchcodec/_core/ops.py", line 69, in load_torchcodec_shared_libraries
    raise RuntimeError(
RuntimeError: Could not load libtorchcodec. Likely causes:
          1. FFmpeg is not properly installed in your environment. We support
             versions 4, 5, 6 and 7.
          2. The PyTorch version (2.9.0+cpu) is not compatible with
             this version of TorchCodec. Refer to the version compatibility
             table:
             https://github.com/pytorch/torchcodec?tab=readme-ov-file#installing-torchcodec.
          3. Another runtime dependency; see exceptions below.
        The following exceptions were raised as we tried to load libtorchcodec:
        
[start of libtorchcodec loading traceback]
FFmpeg version 8: Could not load this library: /home/usern/.local/lib/python3.10/site-packages/torchcodec/libtorchcodec_core8.so
FFmpeg version 7: Could not load this library: /home/usern/.local/lib/python3.10/site-packages/torchcodec/libtorchcodec_custom_ops7.so
FFmpeg version 6: Could not load this library: /home/usern/.local/lib/python3.10/site-packages/torchcodec/libtorchcodec_core6.so
FFmpeg version 5: Could not load this library: /home/usern/.local/lib/python3.10/site-packages/torchcodec/libtorchcodec_core5.so
FFmpeg version 4: Could not load this library: /home/usern/.local/lib/python3.10/site-packages/torchcodec/libtorchcodec_custom_ops4.so
[end of libtorchcodec loading traceback].
Command exited with non-zero status 1

only if:

pip show torch torchaudio
Name: torch
Version: 2.9.0+cpu

works on:

pip show torch torchaudio
Name: torch
Version: 2.8.0+cpu

and older ones. Force reinstalling torch* modules and even apt reinstalling some -dev stuff does not help with the missing .so files.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the torch 2.9.0 and torchaudio 2.9.0 failure on a non-shared Python build, then inspect the installed torchcodec shared objects with ldd as described. The issue names no repository files or tests; done means restoring a portable wheel without the libpython dependency or providing the agreed graceful failure behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
backend, build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.