0

I am trying to convert a text to speech in python using gtts I am using the 3.7.4 version of python but whenever I use gtts ModuleNotFoundError: No module named 'main.gtts'; 'main' is not a package or the sometimes it says gtts module cannot be imported from .gtts import gTTS text2speech = gTTS(text = "HEllo guys",lang = 'en') text2speech.save('sample.mp3') // Traceback (most recent call last): File "C:/Users/DELL/Desktop/text2speech.py", line 1, in from .gtts import gTTS ModuleNotFoundError: No module named 'main.gtts'; 'main' is not a package// please hep me find a solution.

Nilanka Manoj
  • 3,527
  • 4
  • 17
  • 48

2 Answers2

0

its

from gtts import gTTS

instead of

from .gtts import gTTS
Paritosh Yadav
  • 337
  • 1
  • 3
  • 11
  • same error? are you using your environment, can you show your pip list use ```pip list``` – Paritosh Yadav Mar 26 '20 at 06:58
  • C:\Users\DELL>pip list Package Version ----------------- ---------- astroid 2.3.2 beautifulsoup4 4.8.2 certifi 2019.11.28 chardet 3.0.4 Click 7.0 colorama 0.4.1 comtypes 1.1.7 cycler 0.10.0 Django 2.2.5 docopt 0.6.2 future 0.18.2 gTTS 2.1.1 gTTS-token 1.1.3 idna 2.9 – Alan George Mar 27 '20 at 10:04
  • isort 4.3.21 joblib 0.14.0 Js2Py 0.68 kiwisolver 1.1.0 lazy-object-proxy 1.4.3 matplotlib 3.1.1 mccabe 0.6.1 mysqlclient 1.4.4 numpy 1.17.3 packaging 20.3 pandas 0.25.3 pip 20.0.2 pipwin 0.4.7 PyAudio 0.2.11 pyglet 1.5.0 pyjsparser 2.7.1 pylint 2.4.3 pyparsing 2.4.5 PyPrind 2.11.2 python-dateutil 2.8.1 pyttsx3 2.81 – Alan George Mar 27 '20 at 10:06
  • pytz 2019.2 requests 2.23.0 scikit-learn 0.21.3 scipy 1.3.1 setuptools 46.0.0 six 1.12.0 soupsieve 1.9.5 SpeechRecognition 3.8.1 sqlparse 0.3.0 typed-ast 1.4.0 tzlocal 2.0.0 urllib3 1.25.8 wheel 0.34.2 wrapt 1.11.2 – Alan George Mar 27 '20 at 10:08
  • please look over it this is the pip list i have gTTS 2.1.1 – Alan George Mar 27 '20 at 10:14
0

This error: ModuleNotFoundError: No module named '__main__.gtts'; '__main__' is not a package may also occur if you have named the main program file you created as __main__.py and try to run it as python __main__.py or another file has the name __main__.py in the same folder from which you run your program. Python will consider your program file as a module and try to find something in it that is naturally not in it. About where Python is looking for modules, see sys.path.

In this case, rename your program file so that its name does not equal with the name of the imported module.

kirogasa
  • 627
  • 5
  • 19