Skip to content

Import torchcodec fails, "Could not load this library: libtorchcodec_coreX" #1146

@matangover

Description

@matangover

🐛 Describe the bug

Clean install fails on Python 3.10.12 on macOS

mkdir codectest && cd codectest
uv init --python 3.10.12
uv add torch==2.9.1 torchcodec==0.9.1
uv run python -c "import torchcodec"

However, when I use Python 3.11 it succeeds.

Output from importing torchcodec:

/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torch/_subclasses/functional_tensor.py:279: UserWarning: Failed to initialize NumPy: No module named 'numpy' (Triggered internally at /Users/runner/work/pytorch/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:84.)
  cpu = _conversion_method_template(device=torch.device("cpu"))
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/__init__.py", line 12, in <module>
    from . import decoders, encoders, samplers  # noqa
  File "/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/decoders/__init__.py", line 7, in <module>
    from .._core import AudioStreamMetadata, VideoStreamMetadata
  File "/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/_core/__init__.py", line 8, in <module>
    from ._metadata import (
  File "/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/_core/_metadata.py", line 16, in <module>
    from torchcodec._core.ops import (
  File "/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/_core/ops.py", line 104, in <module>
    ffmpeg_major_version, core_library_path = load_torchcodec_shared_libraries()
  File "/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/_core/ops.py", line 75, 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, 7, and 8. On Windows, ensure you've installed
             the "full-shared" version which ships DLLs.
          2. The PyTorch version (2.9.1) 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: /Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core8.dylib
FFmpeg version 7: Could not load this library: /Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core7.dylib
FFmpeg version 6: Could not load this library: /Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core6.dylib
FFmpeg version 5: Could not load this library: /Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core5.dylib
FFmpeg version 4: Could not load this library: /Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core4.dylib
[end of libtorchcodec loading traceback].

Further debugging output:

❯ uv run python
Python 3.10.12 (main, Jul 26 2023, 19:37:41) [Clang 16.0.3 ] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import ctypes
>>> ctypes.CDLL("/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core8.dylib")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/matan/.local/share/uv/python/cpython-3.10.12-macos-aarch64-none/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: dlopen(/Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core8.dylib, 0x0006): Library not loaded: @rpath/libc10.dylib
  Referenced from: <2BA650F4-E163-3EF6-A721-BAA8124FD98E> /Users/matan/code/codectest/.venv/lib/python3.10/site-packages/torchcodec/libtorchcodec_core8.dylib
  Reason: no LC_RPATH's found

Versions

PyTorch version: 2.9.1
Is debug build: False
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: macOS 15.7.3 (arm64)
GCC version: Could not collect
Clang version: 17.0.0 (clang-1700.4.4.1)
CMake version: version 3.31.6
Libc version: N/A

Python version: 3.10.12 (main, Jul 26 2023, 19:37:41) [Clang 16.0.3 ] (64-bit runtime)
Python platform: macOS-15.7.3-arm64-arm-64bit
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
Is XPU available: False
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True
Caching allocator config: N/A

CPU:
Apple M1 Pro

Versions of relevant libraries:
[pip3] Could not collect
[conda] numpy                     1.22.4           py39h7df2422_0    conda-forge

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions