8

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?

QMan5
  • 713
  • 1
  • 4
  • 20

4 Answers4

16

torchtext.data becomes torchtext.legacy.data

from torchtext.legacy.data import Field, TabularDataset, BucketIterator, Iterator
niek tuytel
  • 899
  • 7
  • 18
4
conda install -c pytorch torchtext==0.8

This worked for me on Ubuntu 18.04.

Reza Rahemtola
  • 1,182
  • 7
  • 16
  • 30
okoksal
  • 41
  • 1
  • 3
1

I come up with this when using colab, then I update the torchtext version by

pip install -U torchtext

and it works for me

Ade_1
  • 1,480
  • 1
  • 6
  • 17
1

When I installed torchtext 0.8, the following error occurred, so I installed 0.6 and it was resolved.

undefined symbol: _znk3c104type14issubtypeofextest10shared_ptris0_epso

If there is someone who can't install 0.8, try installing 0.6 with the code below.

pip install -U torchtext==0.6   
ddd
  • 37
  • 6