Why am I getting a ModuleNotFoundError when using googletrans
Question:
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
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
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.
I’ve got the same error and I found out the reason is that I have two Python versions installed (3.7 and 3.8) and the googletrans package was installed only for the one in system path (3.8). What I did is simply use the IDE with 3.8 (I use IDLE and PyCharm as IDE, both are easy to change Python interpreter).
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
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
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.
I’ve got the same error and I found out the reason is that I have two Python versions installed (3.7 and 3.8) and the googletrans package was installed only for the one in system path (3.8). What I did is simply use the IDE with 3.8 (I use IDLE and PyCharm as IDE, both are easy to change Python interpreter).