Installing torchaudio on google colab

Ahmed_m: <p>Hi,</p>
<p>I am trying to install the torchaudio library in google Colaboratory notebook. However I get this dependency error:</p>
<pre><code class="lang-auto">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
</code></pre>
<p>Is there any workaround to fix this issue ?</p>
<p>Best Regards</p>

rasbt: <p>I just installed it via <code>pip</code> on Google Colab directly from the GitHub repo and it works fine.</p>
<pre><code>pip install git+git://github.com/pytorch/audio
</code></pre>
<p><div class="lightbox-wrapper"><a class="lightbox" href="https://discuss.pytorch.org/uploads/default/original/2X/9/95c20cd74909bc9cf2b777a5fbbdc3344123741e.png" data-download-href="https://discuss.pytorch.org/uploads/default/95c20cd74909bc9cf2b777a5fbbdc3344123741e" title="46%20PM"><img src="https://discuss.pytorch.org/uploads/default/optimized/2X/9/95c20cd74909bc9cf2b777a5fbbdc3344123741e_2_690x151.png" alt="46%20PM" data-base62-sha1="lmOTpban3mjqFmsDkQOx5TaTNzo" width="690" height="151" srcset="https://discuss.pytorch.org/uploads/default/optimized/2X/9/95c20cd74909bc9cf2b777a5fbbdc3344123741e_2_690x151.png, https://discuss.pytorch.org/uploads/default/original/2X/9/95c20cd74909bc9cf2b777a5fbbdc3344123741e.png 1.5x, https://discuss.pytorch.org/uploads/default/original/2X/9/95c20cd74909bc9cf2b777a5fbbdc3344123741e.png 2x" data-dominant-color="F5F5F5"><div class="meta"><svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use href="#far-image"></use></svg><span class="filename">46%20PM</span><span class="informations">880×193 26 KB</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use href="#discourse-expand"></use></svg></div></a></div></p>
<p>Note that you need to install the required dependencies via <code>apt-get</code> first as mentioned in the GitHub repo. Also you need to have PyTorch installed, otherwise you will get an error during the install.</p>
<p>EDIT:</p>
<p>The dependencies I mentioned above are the ones listed for Ubuntu Linux (<a href="https://github.com/pytorch/audio#dependencies" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pytorch/audio: Data manipulation and transformation for audio signal processing, powered by PyTorch</a>). Worked fine for me in the Colaboratory Notebook:</p>
<pre><code>apt-get install sox libsox-dev libsox-fmt-all
</code></pre>

Ahmed_m: <p>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</p>

100deep1001: <p>Tried the following:</p>
<p><code>!sudo apt-get install sox libsox-dev libsox-fmt-all</code><br>
<code>!pip install git+git://github.com/pytorch/audio</code></p>
<p>Got the following message:<br>
<code>Successfully built torchaudio</code></p>
<p>However, got the following error while importing torchaudio:<br>
<code>import torchaudio</code><br>
<code>RuntimeError: Failed to parse the argument list of a type annotation: name 'Optional' is not defined</code></p>
<p>Am I missing something?</p>

100deep1001: <p>This worked finally:</p>
<pre><code class="lang-auto">!git clone https://github.com/pytorch/audio.git
os.chdir("audio")
!git checkout 301e2e9
!python setup.py install
</code></pre>
<p>Source : <a href="https://github.com/pytorch/audio/issues/71" rel="nofollow noopener">https://github.com/pytorch/audio/issues/71</a></p>

PalaashAgrawal: <p>This works! Thankyou so much</p>

TPU: <p>If you stumble upon this thread in 2021, you can install the latest pip wheel in Colab as follows:</p>
<pre><code class="lang-auto">!pip install torchaudio -f https://download.pytorch.org/whl/torch_stable.html
</code></pre>
<p>and then restart the runtime.</p>
<p>(Check <a href="https://github.com/pytorch/audio" class="inline-onebox" rel="noopener nofollow ugc">GitHub - pytorch/audio: Data manipulation and transformation for audio signal processing, powered by PyTorch</a>)</p>

gug: <p>If u are facing a problem  in Nov 2021, you can try</p>
<pre><code class="lang-auto">!pip uninstall -y torchaudio

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

</code></pre>
<p>this will first uninstall the current version(if exists) and will download the stable version</p>

new_here: <p><a class="mention" href="/u/gug">@gug</a> Thanks for the instructions, but they don’t seem to help unfortunately.</p>
<p>On colab, I still get<br>
ModuleNotFoundError: No module named ‘torchaudio.prototype’</p>
<p>Try it for yourself using the ctcdecoder - <a href="https://colab.research.google.com/github/pytorch/audio/blob/gh-pages/main/_downloads/ade1a3c3b444796d2a34839c7ea75426/asr_inference_with_ctc_decoder_tutorial.ipynb#scrollTo=sJkOlyNIFMKj" class="inline-onebox" rel="noopener nofollow ugc">Google Colab</a></p>

gug: <p>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!<br>
link for docs github - <a href="https://github.com/pytorch/tutorials/issues" rel="noopener nofollow ugc">pytorch-tutorials</a><br>
link for the audio - <a href="https://github.com/pytorch/audio/issues" rel="noopener nofollow ugc">torchaudio</a><br>
meanwhile I will try to resolve if I can <img src="https://discuss.pytorch.org/images/emoji/apple/slight_smile.png?v=12" title=":slight_smile:" class="emoji" alt=":slight_smile:" loading="lazy" width="20" height="20"></p>

gug: <p>I think the reason for the the error lies in the <code>__init__</code> of torchaudio module.<br>
maybe adding reference to prototype module in init will help (you can do it in your local copy)</p>

gug: <p><a href="https://github.com/pytorch/audio/blob/main/torchaudio/__init__.py" rel="noopener nofollow ugc">torchaudio init</a></p>

nateanl: <p>Hi <a class="mention" href="/u/new_here">@new_here</a>,</p>
<blockquote>
<p>On colab, I still get<br>
ModuleNotFoundError: No module named ‘torchaudio.prototype’</p>
</blockquote>
<p>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<br>
<code>pip3 install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html</code></p>

barakb: <p>I’m trying to understand prototype was in previous versions and is no longer supported?<br>
If so, does torchaudion has no “beamsearch” decoding? I couldn’t find any replacement.</p>

nateanl: <p>Hi <a class="mention" href="/u/barakb">@barakb</a>, the prototype features are still maintained in torchaudio, you can use the CTC beamsearch decoder by installing the <strong>nightly</strong> torchaudio.<br>
Here is the command for installing nightly version with CUDA 10.2:</p>
<pre><code class="lang-bash">pip3 install --pre torch torchvision torchaudio -f https://download.pytorch.org/whl/nightly/cu102/torch_nightly.html
</code></pre>

barakb: <p>Hi I saw your previous answer, but it didn’t help me.<br>
I’m still trying to understand, is it a future feature that is still not stable or a deprecated feature?<br>
Thanks for your help</p>

nateanl: <p>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.</p>
<p>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.</p>

barakb: <p>Thanks a lot for the explanation!!</p>