0

我在使用 torctext 时出错:

ModuleNotFoundError                       Traceback (most recent call last)
<ipython-input-65-e34e6e6439d5> in <module>
      1 import torch
      2 from torchtext.experimental.datasets.text_classification import TextClassificationDataset
----> 3 from torchtext.experimental.vocab import build_vocab_from_iterator
      4 from torchtext.data.utils import get_tokenizer
      5 from torchtext.experimental.functional import sequential_transforms, vocab_func, totensor

~\anaconda3\envs\env_pytorch\lib\site-packages\torchtext\experimental\vocab.py in <module>
      5 import torch
      6 import torch.nn as nn
----> 7 from torchtext._torchtext import (
      8     Vocab as VocabPybind,
      9     _load_vocab_from_file,

ModuleNotFoundError: No module named 'torchtext._torchtext'

我试图将“torchtext”目录放在 jupiter notebook 的文件夹中,但再次出现错误

~\Desktop\Competition\VTB\Task 1\torchtext\experimental\transforms.py in <module>
      5 from collections import OrderedDict
      6 from torch import Tensor
----> 7 from torchtext._torchtext import SentencePiece as SentencePiecePybind
      8 import io
      9 

ModuleNotFoundError: No module named 'torchtext._torchtext
4

1 回答 1

0

如果您使用源代码文件,您可以尝试删除此文件并运行命令:

pip install torchtext
于 2021-10-21T07:17:22.470 回答