0

Why can't I import vocab when using torchtext?

from torchtext.vocab import Vocab, vocab

results in:

Python 3.8.2 (default, Mar 26 2020, 15:53:00) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from torchtext.vocab import Vocab, vocab


Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: cannot import name 'vocab' from 'torchtext.vocab' (/home/miranda9/miniconda3/envs/metalearningpy1.7.1c10.2/lib/python3.8/site-packages/torchtext/vocab.py)

but my version seem compatible:

(metalearningpy1.7.1c10.2) miranda9~/automl-meta-learning $ pip list | grep torch

torch                  1.7.1
torchaudio             0.7.0a0+a853dff
torchmeta              1.7.0
torchtext              0.8.0a0+0f911ec
torchvision            0.8.2

from reading this question: torchtext ImportError in colab


related:

Charlie Parker
  • 5,884
  • 57
  • 198
  • 323

1 Answers1

0

Seems that it does work on my other env:

(synthesis) miranda9~/ultimate-utils/ultimate-utils-proj-src $ pip list | grep torch
torch                   1.9.0
torchtext               0.10.0
(synthesis) miranda9~/ultimate-utils/ultimate-utils-proj-src $ python
Python 3.9.6 (default, Aug 18 2021, 19:38:01) 
[GCC 7.5.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from torchtext.vocab import Vocab, vocab
Charlie Parker
  • 5,884
  • 57
  • 198
  • 323