audio: Cannot import torchaudio with torch 1.1

I am trying to use torchaudio with torch 1.1. It compiled successfully with Python 3.6, but when I want to import the torchaudio package, I get this error:

>>> import torchaudio
Traceback (most recent call last):
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torch/jit/annotations.py", line 95, in parse_type_line
    arg_ann = eval(arg_ann_str, _eval_env)
  File "<string>", line 1, in <module>
NameError: name 'Optional' is not defined

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torchaudio-0.2-py3.6-linux-x86_64.egg/torchaudio/__init__.py", line 7, in <module>
    from torchaudio import transforms, datasets, kaldi_io, sox_effects, legacy
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torchaudio-0.2-py3.6-linux-x86_64.egg/torchaudio/transforms.py", line 6, in <module>
    from . import functional as F
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torchaudio-0.2-py3.6-linux-x86_64.egg/torchaudio/functional.py", line 108, in <module>
    @torch.jit.script
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torch/jit/__init__.py", line 824, in script
    fn = torch._C._jit_script_compile(ast, _rcb, get_default_args(obj))
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/site-packages/torch/jit/annotations.py", line 55, in get_signature
    return parse_type_line(type_line)
  File "/home/daniel/envs/pytorch-py3/lib/python3.6/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

It ran fine on torch 1.0 - maybe some problem with differing source code between torch 1.0 and 1.1?

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 18
  • Comments: 24 (7 by maintainers)

Most upvoted comments

Yes this is a known issue. We are currently working on a fix and will update this when resolved

same issue, working after I check out d92de5b97fc6204db4b1e3ed20c03ac06f5d53f0

Thanks a lot @jamarshon , I solved this error by pip uninstall torchaudio; git checkout d92de5b; python setup.py install.

@MNCTTY For your first issue about UndefinedTensorImp, it is mentioned here https://discuss.pytorch.org/t/torchaudio-import-error/48367 where you have to upgrade your pytorch version (e.g 1.1.0)

For your second issue, you did not checkout the specific commit. You can do this by running git clone --branch v0.2.0 https://github.com/pytorch/audio.git or if you already cloned it you can do git checkout d92de5b as mentioned by tobyclh. When it says No module named torch.utils.cpp_extension, could you try running

# >> python
import torch
print(torch.__version__)

and seeing that you can in fact import the module and that it is the correct version? I looked at v1.0.0 and it has the file torch.utils.cpp_extension.py.

Let us know if those steps still do not work for you

Same issue. I downgraded pytorch to version 1.0.0 and then installed audio as pip3 install git+https://github.com/pytorch/audio@d92de5b it has been built successfully, but when I tried to import, I recieved this error: image I couldn’t google anything (all mentions by the error was about maskrcnn, I didn’t find some correspondings)

After that I tried to build audio from git as it is recommended: git clone https://github.com/pytorch/audio.git and then cd audio; python setup.py install and it gives me the following traceback: image I tried to do recommendations from here - https://github.com/pytorch/audio/issues/49 - but it nothing has changed In other issue people say that people, who meet the same error, use old versions of torch (0.3 and others), but I use 1.0.0

I use python 3.5, cuda 10.1, Ubuntu 16.04.6 LTS (Xenial Xerus)

Does someone have any ideas?

if you use conda and open to downgrade, this works to me. conda install pytorch==1.1.0 torchvision==0.3.0 cudatoolkit=10.0 torchaudio=0.2.0 -c pytorch

I managed to fix it: #254