Installing torchaudio on google colab

Hi,

I am trying to install the torchaudio library in google Colaboratory notebook. However I get this dependency error:

running install
running bdist_egg
running egg_info
creating torchaudio.egg-info
writing torchaudio.egg-info/PKG-INFO
writing dependency_links to torchaudio.egg-info/dependency_links.txt
writing top-level names to torchaudio.egg-info/top_level.txt
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
reading manifest file 'torchaudio.egg-info/SOURCES.txt'
writing manifest file 'torchaudio.egg-info/SOURCES.txt'
installing library code to build/bdist.linux-x86_64/egg
running install_lib
running build_ext
building '_torch_sox' extension
creating build
creating build/temp.linux-x86_64-3.6
creating build/temp.linux-x86_64-3.6/torchaudio
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -g -fdebug-prefix-map=/build/python3.6-sXpGnM/python3.6-3.6.3=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2 -fPIC -I/usr/local/lib/python3.6/dist-packages/torch/lib/include -I/usr/local/lib/python3.6/dist-packages/torch/lib/include/TH -I/usr/local/lib/python3.6/dist-packages/torch/lib/include/THC -I/usr/include/python3.6m -c torchaudio/torch_sox.cpp -o build/temp.linux-x86_64-3.6/torchaudio/torch_sox.o -DTORCH_EXTENSION_NAME=_torch_sox -std=c++11
x86_64-linux-gnu-gcc: error: torchaudio/torch_sox.cpp: No such file or directory
x86_64-linux-gnu-gcc: fatal error: no input files
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

Is there any workaround to fix this issue ?

Best Regards

I just installed it via pip on Google Colab directly from the GitHub repo and it works fine.

pip install git+git://github.com/pytorch/audio

Note that you need to install the required dependencies via apt-get first as mentioned in the GitHub repo. Also you need to have PyTorch installed, otherwise you will get an error during the install.

EDIT:

The dependencies I mentioned above are the ones listed for Ubuntu Linux (GitHub - pytorch/audio: Data manipulation and transformation for audio signal processing, powered by PyTorch). Worked fine for me in the Colaboratory Notebook:

apt-get install sox libsox-dev libsox-fmt-all
5 Likes

Actually I was installing it manually and found that I should have installed ā€˜cffiā€™ first as additional dependency. However the direct installation via pip you have provided is awesome. Thaanks

Tried the following:

!sudo apt-get install sox libsox-dev libsox-fmt-all
!pip install git+git://github.com/pytorch/audio

Got the following message:
Successfully built torchaudio

However, got the following error while importing torchaudio:
import torchaudio
RuntimeError: Failed to parse the argument list of a type annotation: name 'Optional' is not defined

Am I missing something?

This worked finally:

!git clone https://github.com/pytorch/audio.git
os.chdir("audio")
!git checkout 301e2e9
!python setup.py install

Source : https://github.com/pytorch/audio/issues/71

This works! Thankyou so much

If you stumble upon this thread in 2021, you can install the latest pip wheel in Colab as follows:

!pip install torchaudio -f https://download.pytorch.org/whl/torch_stable.html

and then restart the runtime.

(Check GitHub - pytorch/audio: Data manipulation and transformation for audio signal processing, powered by PyTorch)

2 Likes

If u are facing a problem in Nov 2021, you can try

!pip uninstall -y torchaudio

!pip3 install torchaudio==0.10.0 -f https://download.pytorch.org/whl/cu111/torch_stable.html

this will first uninstall the current version(if exists) and will download the stable version

1 Like

@gug Thanks for the instructions, but they donā€™t seem to help unfortunately.

On colab, I still get
ModuleNotFoundError: No module named ā€˜torchaudio.prototypeā€™

Try it for yourself using the ctcdecoder - Google Colab

Hmmm; seems like there is an issue with the torchaudio! could you raise an issue on torchaudio and pytorch-docs? so that it will get fixed and people wonā€™t face problems in future!
link for docs github - pytorch-tutorials
link for the audio - torchaudio
meanwhile I will try to resolve if I can :slight_smile:

I think the reason for the the error lies in the __init__ of torchaudio module.
maybe adding reference to prototype module in init will help (you can do it in your local copy)

torchaudio init

Hi @new_here,

On colab, I still get
ModuleNotFoundError: No module named ā€˜torchaudio.prototypeā€™

This is expected, as the prototype feature is removed from the official release. If you want to try the CTC Decoder, you can install the nightly-build of torchaudio by
pip3 install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html

1 Like

Iā€™m trying to understand prototype was in previous versions and is no longer supported?
If so, does torchaudion has no ā€œbeamsearchā€ decoding? I couldnā€™t find any replacement.

Hi @barakb, the prototype features are still maintained in torchaudio, you can use the CTC beamsearch decoder by installing the nightly torchaudio.
Here is the command for installing nightly version with CUDA 10.2:

pip3 install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html

Hi I saw your previous answer, but it didnā€™t help me.
Iā€™m still trying to understand, is it a future feature that is still not stable or a deprecated feature?
Thanks for your help

Sorry for misunderstanding. In general if a feature is a prototype feature, itā€™s a future feature and may be refactored faster than stable feature. It will not be included in the official release like 0.10.0 or 0.11.0.

Once it is stable, the feature will be moved out of prototype folder into a stable one, then itā€™ll be included in the next official release.

1 Like

Thanks a lot for the explanation!!