Error occurred when I tried to import torchaudio

Kai_Qu1: <p>I installed torchaudio according to the instruction by <a href="https://github.com/pytorch/audio" rel="nofollow noopener">https://github.com/pytorch/audio</a>. Nevertheless, when I tried to import torchaudio, the following error message popped up:</p>
<p>Traceback (most recent call last):<br>
File “test.py”, line 1, in <br>
import torchaudio<br>
File “/Users/q7/Desktop/Wavenet/audio-master/torchaudio/<strong>init</strong>.py”, line 7, in <br>
from torchaudio import transforms, datasets, kaldi_io, sox_effects, legacy, compliance<br>
File “/Users/q7/Desktop/Wavenet/audio-master/torchaudio/transforms.py”, line 6, in <br>
from . import functional as F<br>
File “/Users/q7/Desktop/Wavenet/audio-master/torchaudio/functional.py”, line 108, in <br>
<span class="mention">@torch.jit.script</span><br>
File “/anaconda3/lib/python3.7/site-packages/torch/jit/<strong>init</strong>.py”, line 824, in script<br>
fn = torch._C._jit_script_compile(ast, _rcb, get_default_args(obj))<br>
File “/anaconda3/lib/python3.7/site-packages/torch/jit/annotations.py”, line 55, in get_signature<br>
return parse_type_line(type_line)<br>
File “/anaconda3/lib/python3.7/site-packages/torch/jit/annotations.py”, line 97, in parse_type_line<br>
raise RuntimeError(“Failed to parse the argument list of a type annotation: {}”.format(str(e)))<br>
RuntimeError: Failed to parse the argument list of a type annotation: name ‘Optional’ is not defined</p>
<p>Can someone propose a solution? Thanks a lot.</p>

rfalcon100: <p>I am having the same problem. Using torch 1.1.0.</p>

Maksim_Pershin: <p>There was bad commit in torchaudio. Solution: old version with pytorch 1.0.<br>
pip3 install git+https://github.com/pytorch/audio@d92de5b</p>

100deep1001: <aside class="quote no-group" data-username="Maksim_Pershin" data-post="4" data-topic="48582">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/maksim_pershin/48/13364_2.png" class="avatar"> Maksim_Pershin:</div>
<blockquote>
<p>pip3 install git+https://github.com/pytorch/audio@d92de5b</p>
</blockquote>
</aside>
<p>Any other alternative?<br>
This fails on current version<br>
<code>transform = torchaudio.transforms.DownmixMono(channels_first=True)</code><br>
<code>__init__() got an unexpected keyword argument 'channels_first'</code></p>
<p>The  <code>__init__</code>  method just contains a  <code>pass</code>  statement.</p>

johan010: <p>I also have the same issue.</p>
<p>edit:<br>
Used Maksim_Pershin’s old version successfully for now.</p>

100deep1001: <p>Can you try this?</p>
<pre><code class="lang-auto">import sys
sys.version
'3.6.8 (default, Jan 14 2019, 11:02:34) \n[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]'
</code></pre>
<pre><code class="lang-auto">!cat /usr/local/cuda/version.txt
CUDA Version 10.0.130
</code></pre>
<pre><code class="lang-auto"># Install dependencies
!apt-get install sox libsox-dev libsox-fmt-all
</code></pre>
<p>Go to <a href="https://pytorch.org/get-started/locally/" rel="nofollow noopener">the following link and check for links corresponding to your python and CUDA versions</a><br>
<div class="lightbox-wrapper"><a class="lightbox" href="https://user-images.githubusercontent.com/25292456/61643300-2d95c880-acc0-11e9-9c17-136ef854a1e4.png" title="61643300-2d95c880-acc0-11e9-9c17-136ef854a1e4.png" rel="nofollow noopener"><img src="https://user-images.githubusercontent.com/25292456/61643300-2d95c880-acc0-11e9-9c17-136ef854a1e4.png" alt="image" width="690" height="252"><div class="meta">
<svg class="fa d-icon d-icon-far-image svg-icon" aria-hidden="true"><use xlink:href="#far-image"></use></svg><span class="filename">61643300-2d95c880-acc0-11e9-9c17-136ef854a1e4.png</span><span class="informations">1135×416</span><svg class="fa d-icon d-icon-discourse-expand svg-icon" aria-hidden="true"><use xlink:href="#discourse-expand"></use></svg>
</div></a></div></p>
<pre><code class="lang-auto">!pip3 install https://download.pytorch.org/whl/cu100/torch-1.1.0-cp36-cp36m-linux_x86_64.whl
!pip3 install https://download.pytorch.org/whl/cu100/torchvision-0.3.0-cp36-cp36m-linux_x86_64.whl
</code></pre>
<pre><code class="lang-auto"># install torchaudio
!pip install git+https://github.com/pytorch/audio.git@v0.2.0
</code></pre>
<pre><code class="lang-auto"># Run torchaudio
import torchaudio
print(torchaudio.__version__)  # prints 0.2.0a0+7d7342f
</code></pre>