pythonpytorchtorchtext

AttributeError: module 'torchtext.data' has no attribute 'Field' not fixed with torchtext.legacy


I am trying to use torchtext.data.Field() from torchtext but it is not working in any way I have tried.

I have tried with from torchtext.legacy import data but it does not seem to work. I have also tried to install another version of torchtext (currently have 0.16.2) by running pip install torchtext==0.10.0 but I get this error message in the terminal

ERROR: Could not find a version that satisfies the requirement torchtext==0.10.0 (from versions: 0.1.1, 0.2.0, 0.2.1, 0.2.3, 0.3.1, 0.4.0, 0.5.0, 0.6.0, 0.16.2)
ERROR: No matching distribution found for torchtext==0.10.0

Has anyone experienced this error before?

I am using a conda environment with Python version 3.12.1 and my torch version is 2.2.0.


Solution

  • torchtext is supported till python 3.11

    https://pypi.org/project/torchtext/

    You need to downgrade to python 3.11 or install python 3.11 separately to work with torchtext

    enter image description here