Search code examples
pythonimporterrortorch

Getting ImportError when using torchtext


I'm getting the following error when I try to run this line of code:

from torchtext.data import Field, TabularDataset, BucketIterator, Iterator


ImportError: cannot import name 'Field' from 'torchtext.data' (C:\Users\user1\anaconda3\lib\site-packages\torchtext\data\__init__.py)

I was wondering if anyone knows what the issue might be and how to resolve it?


Solution

  • torchtext.data becomes torchtext.legacy.data

    from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator