Error occurred when I tried to import torchaudio

I installed torchaudio according to the instruction by https://github.com/pytorch/audio. Nevertheless, when I tried to import torchaudio, the following error message popped up:

Traceback (most recent call last):
File “test.py”, line 1, in
import torchaudio
File “/Users/q7/Desktop/Wavenet/audio-master/torchaudio/init.py”, line 7, in
from torchaudio import transforms, datasets, kaldi_io, sox_effects, legacy, compliance
File “/Users/q7/Desktop/Wavenet/audio-master/torchaudio/transforms.py”, line 6, in
from . import functional as F
File “/Users/q7/Desktop/Wavenet/audio-master/torchaudio/functional.py”, line 108, in
@torch.jit.script
File “/anaconda3/lib/python3.7/site-packages/torch/jit/init.py”, line 824, in script
fn = torch._C._jit_script_compile(ast, _rcb, get_default_args(obj))
File “/anaconda3/lib/python3.7/site-packages/torch/jit/annotations.py”, line 55, in get_signature
return parse_type_line(type_line)
File “/anaconda3/lib/python3.7/site-packages/torch/jit/annotations.py”, line 97, in parse_type_line
raise RuntimeError(“Failed to parse the argument list of a type annotation: {}”.format(str(e)))
RuntimeError: Failed to parse the argument list of a type annotation: name ‘Optional’ is not defined

Can someone propose a solution? Thanks a lot.

I am having the same problem. Using torch 1.1.0.

1 Like

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

Any other alternative?
This fails on current version
transform = torchaudio.transforms.DownmixMono(channels_first=True)
__init__() got an unexpected keyword argument 'channels_first'

The __init__ method just contains a pass statement.

I also have the same issue.

edit:
Used Maksim_Pershin’s old version successfully for now.

Can you try this?

import sys
sys.version
'3.6.8 (default, Jan 14 2019, 11:02:34) \n[GCC 8.0.1 20180414 (experimental) [trunk revision 259383]]'
!cat /usr/local/cuda/version.txt
CUDA Version 10.0.130
# Install dependencies
!apt-get install sox libsox-dev libsox-fmt-all

Go to the following link and check for links corresponding to your python and CUDA versions

!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
# install torchaudio
!pip install git+https://github.com/pytorch/audio.git@v0.2.0
# Run torchaudio
import torchaudio
print(torchaudio.__version__)  # prints 0.2.0a0+7d7342f
1 Like