From b8e0baa5c34c2896716331a48a13b134beae77ee Mon Sep 17 00:00:00 2001 From: Alex Bondarev Date: Tue, 21 Apr 2026 15:30:57 -0500 Subject: [PATCH] Declare torch as a runtime dependency torchaudio imports torch unconditionally at package init, so pip install torchaudio into an environment without a separate pip install torch fails with ModuleNotFoundError. Restore the _get_pytorch_version() call that was commented out in #4171. This matches the pattern used in pytorch/vision and pytorch/text: - Local / dev builds: install_requires = ["torch"] (unpinned). - Release builds (PYTORCH_VERSION env var set by the release builder): install_requires = ["torch==X.Y.Z"], preserving the ABI-match guarantee that historical torchaudio releases shipped with. The in-thread comment on #4171 flagged that an unpinned dep would be enough to keep pip's resolver correct: https://github.com/pytorch/audio/pull/4171#issuecomment-2715 --- setup.py | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/setup.py b/setup.py index 8030c5408e..06b938bb31 100644 --- a/setup.py +++ b/setup.py @@ -86,12 +86,8 @@ def _main(): print("-- Git branch:", branch) print("-- Git SHA:", sha) print("-- Git tag:", tag) - # This used to be passed to install_requires - # which would cause pinning against a specific torch version in releases. - # I don't think we want to pin at all? - # TODO: revisit if needed. Maybe it's needed for nightlies. Unsure. - # pytorch_package_dep = _get_pytorch_version() - # print("-- PyTorch dependency:", pytorch_package_dep) + pytorch_package_dep = _get_pytorch_version() + print("-- PyTorch dependency:", pytorch_package_dep) version = _get_version(sha) print("-- Building version", version) @@ -139,7 +135,7 @@ def _main(): "build_ext": setup_helpers.get_build_ext(), "clean": clean, }, - install_requires=[], + install_requires=[pytorch_package_dep], zip_safe=False, )