Unlike Java, where you do something like import module.submodule.blah.blah.MyClass
, in Python, you can only directly import modules. If you want to only import a certain class, function, or other named value from a module, you need to use the from ... import ...
syntax.
In all likelihood, gtts
is a module, and gTTS
is a class within that module. Therefore, import gtts.gTTS
makes no sense, since gTTS
isn't a module (that's what the error says), you must use from gtts import gTTS
For example, import os.path
works fine, since path
is a submodule of os
, but if I wanted to use the exists
function in path
, I would need to use from os.path import exists
or import os.path; os.path.exists(...)
. I get a ModuleNotFoundError if I erroneously try import os.path.exsts
.