Search code examples
pythonapipycharmgoogle-translator-toolkitgoogletrans

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


Solution

  • 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