Python voice assistant "ModuleNotFoundError: No module named 'gtts"

2.1k Views Asked by At

I'm trying to make a voice assistant with python in VSCode but have trouble. I installed all modules already, but one of the modules is not working. The gTTs(Google Text-to-Speech) make a error which is:

ModuleNotFoundError: No module named 'gtts'

I installed gTTs with pip installer in the terminal, again and again, but it did not happen anything. It just shows me:

"Requirement already satisfied"
import speech_recognition as sr
from gtts import gTTS
import os
import time
import playsound

def speak(text):
    tts = gTTS(text=text, lang='en')
    filename = 'jarvis_email_alert.mp3'
    tts.save(filename)
    playsound.playsound(filename)

    speak("hello time")

gTTS error

in code line

PS C:\Users\huzey\OneDrive\Masaüstü\Python> &  C:/Users/huzey/AppData/Local/Microsoft/WindowsApps/python3.8.exe 
c:/Users/huzey/OneDrive/Masaüstü/Python/main.py
Traceback (most recent call last):
    File "c:/Users/huzey/OneDrive/Masaüstü/Python/main.py", line 2, in <module>
    from gtts import gTTS
ModuleNotFoundError: No module named 'gtts'
PS C:\Users\huzey\OneDrive\Masaüstü\Python> 

How can I get the solution?

3

There are 3 best solutions below

0
On

I fixed that problem. İt seemed my system have two different python version. After realizing that I remove all pythons in system and install only one version of python. Before doing this when I open CMD and checking python version I seemed python 3.10 but the same time when I open VS code and checking python version it was showing me version of python 3.8. Now system have version of python 3.8.10 and working clearly! (after fixing a few line errors :))

Thank you for your ideas.

1
On

it might be that your pip is using a different python version than your script

you can use python -m pip install gtts to install gtts to your python environment

2
On

If you didn't, try to restart Vscode after a pip install