2

I want to run PyTorch code on Linux. I start a virtual machine on AWS with AMI Deep Learning PyTorch, but, surprisingly, PyTorch is not installed. So I run:

python3 -m pip install torch torchaudio

When I load a WAV file, I get this error:

RuntimeError: Couldn't find appropriate backend to handle uri /path/to/file.wav and format None.

Reading this thread, I install sox:

python3 -m pip install sox

but I get the same error. Reading this thread, I test this code:

import torchaudio
print(torchaudio.utils.sox_utils.list_read_formats())

and I get this error:

Traceback (most recent call last):
  File "/opt/conda/lib/python3.10/site-packages/torchaudio/_extension/utils.py", line 207, in wrapped
    _init_sox()
  File "/opt/conda/lib/python3.10/site-packages/torchaudio/_extension/utils.py", line 70, in _init_sox
    _load_lib("libtorchaudio_sox")
  File "/opt/conda/lib/python3.10/site-packages/torchaudio/_extension/utils.py", line 64, in _load_lib
    torch.ops.load_library(path)
  File "/opt/conda/lib/python3.10/site-packages/torch/_ops.py", line 852, in load_library
    ctypes.CDLL(path)
  File "/opt/conda/lib/python3.10/ctypes/__init__.py", line 374, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libsox.so: cannot open shared object file: No such file or directory

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/conda/lib/python3.10/site-packages/torchaudio/_extension/utils.py", line 209, in wrapped
    raise RuntimeError(
RuntimeError: list_read_formats requires sox extension which is not available. Please refer to the stacktrace above for how to resolve this.

so I install sox with:

sudo apt-get install -y sox

and I confirm that it works:

$ which sox
/usr/bin/sox

I restart the Python3 REPL, and the virtual machine too, and I get the same errors.

How can I install sox for use with PyTorch audio?

2
  • 1
    It seems you are missing libsox.so. Can you find this file on your system? Perhaps it is called libsox.so.3 or something similar, in that case make a symlink so that libsox.so also exists. You can also try running sudo ldconfig
    – C-nan
    Commented Dec 5, 2023 at 6:40
  • @C-nan No, I can't find libsox.so with find / -type f -name libsox.so, nor with find / -type f -name libsox.so.3. And yet sox is installed with version SoX v14.4.2.
    – emonigma
    Commented Dec 5, 2023 at 18:23

1 Answer 1

5

I had the same issue you need to install libsox-dev package

sudo apt install libsox-dev

This solution worked for me on ubuntu

1
  • Problem solved.
    – ZR Han
    Commented Jan 8 at 2:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .