Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why am I getting a ModuleNotFoundError when using googletrans

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

like image 411
Shoto Avatar asked Sep 08 '25 07:09

Shoto


2 Answers

Install googletrans with pip install googletrans. If you get a ModulNotFoundError you have not installed googletrans correctly.

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)

You have multiple mistakes in your code. It's items() and not item() and the variable translator was misspelled in the last line.

The output of your program is:

Cómo convertir un texto a varios idiomas
如何将一些文本转换为多种语言
Come convertire del testo in più lingue
like image 58
Habebit Avatar answered Sep 10 '25 12:09

Habebit


I think you need to pip install googletrans for you system python means you can deactivate the virtual environment and pip install googletrans and then activate the virtualenv again.

like image 39
Syed Adnan Haider Avatar answered Sep 10 '25 11:09

Syed Adnan Haider