为什么使用torchtext
不能导入vocab
from torchtext.vocab import Vocab, vocab
结果:
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)
但我的版本似乎兼容:
(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
从阅读这个问题:torchtext importterror in colab
相关:- 如何在HPC中安装pytorch 1.9,似乎拒绝合作?
似乎它在我的其他环境中起作用:
(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