3

I have pip installed googletrans and more or less copied this code off a video but for some reason it cannot find the module.

from googletrans import Translator
text=("How to convert some text to multiple languages")
destination_langauge={
    "Spanish": "es",
    "Chinese":"zh-CN",
    "Italian":"it"}
translator=Translator()
for key, value in destination_language.item():
    print(tranlator.translate(text, dest=value).text)

Any help will be greatly appreciated because I am struggling

4

2 回答 2

2

安装。googletrans_ pip install googletrans如果你得到一个ModulNotFoundError你没有正确安装 googletrans。

from googletrans import Translator

text=("How to convert some text to multiple languages")
destination_language = {
    "Spanish": "es",
    "Chinese":"zh-CN",
    "Italian":"it"
}
translator=Translator()
for key, value in destination_language.items():
    print(translator.translate(text, dest=value).text)

您的代码中有多个错误。它是items()和不是item(),变量translator在最后一行拼写错误。

你的程序的输出是:

Cómo convertir un texto a varios idiomas
如何将一些文本转换为多种语言
Come convertire del testo in più lingue
于 2019-02-21T16:18:57.100 回答
1

我认为您需要 pip install googletrans 为您的系统 python 意味着您可以停用虚拟环境并 pip install googletrans 然后再次激活 virtualenv。

于 2021-01-08T11:09:18.380 回答