ModuleNotFoundError No module named pythoncom in pyttsx3

0 votes
import pyttsx3

engine = pyttsx3.init()

in this code i have ploblem

ModuleNotFoundError: No module named 'pythoncom'  in pyttsx3
Apr 15, 2020 in Python by Ashmit
• 120 points
13,929 views
try pip install pywin32
Thank you so much sir
can anyone solve this

this is my code

import pyttsx3
import webbrowser
import smtplib
import random
import speech_recognition as sr
import wikipedia
import datetime
import wolframalpha
import os
import sys

engine = pyttsx3.init('sapi5')

client = wolframalpha.Client('Your_App_ID')

voices = engine.getProperty('voices')
engine.setProperty('voice', voices[len(voices)-1].id)

def speak(audio):
    print('Computer: ' + audio)
    engine.say(audio)
    engine.runAndWait()

def greetMe():
    currentH = int(datetime.datetime.now().hour)
    if currentH >= 0 and currentH < 12:
        speak('Good Morning!')

    if currentH >= 12 and currentH < 18:
        speak('Good Afternoon!')

    if currentH >= 18 and currentH !=0:
        speak('Good Evening!')

greetMe()

speak('Hello Sir, I am your digital assistant LARVIS the Lady Jarvis!')
speak('How may I help you?')

def myCommand():
  
    r = sr.Recognizer()                                                                                  
    with sr.Microphone() as source:                                                                      
        print("Listening...")
        r.pause_threshold =  1
        audio = r.listen(source)
    try:
        query = r.recognize_google(audio, language='en-in')
        print('User: ' + query + '\n')
       
    except sr.UnknownValueError:
        speak('Sorry sir! I didn\'t get that! Try typing the command!')
        query = str(input('Command: '))

    return query
       

if __name__ == '__main__':

    while True:
   
        query = myCommand();
        query = query.lower()
       
        if 'open youtube' in query:
            speak('okay')
            webbrowser.open('www.youtube.com')

        elif 'open google' in query:
            speak('okay')
            webbrowser.open('www.google.co.in')

        elif 'open gmail' in query:
            speak('okay')
            webbrowser.open('www.gmail.com')

        elif "what\'s up" in query or 'how are you' in query:
            stMsgs = ['Just doing my thing!', 'I am fine!', 'Nice!', 'I am nice and full of energy']
            speak(random.choice(stMsgs))

        elif 'email' in query:
            speak('Who is the recipient? ')
            recipient = myCommand()

            if 'me' in recipient:
                try:
                    speak('What should I say? ')
                    content = myCommand()
       
                    server = smtplib.SMTP('smtp.gmail.com', 587)
                    server.ehlo()
                    server.starttls()
                    server.login("Your_Username", 'Your_Password')
                    server.sendmail('Your_Username', "Recipient_Username", content)
                    server.close()
                    speak('Email sent!')

                except:
                    speak('Sorry Sir! I am unable to send your message at this moment!')

        elif 'nothing' in query or 'abort' in query or 'stop' in query:
            speak('okay')
            speak('Bye Sir, have a good day.')
            sys.exit()
          
        elif 'hello' in query:
            speak('Hello Sir')

        elif 'bye' in query:
            speak('Bye Sir, have a good day.')
            sys.exit()
                                   
        elif 'play music' in query:
            music_folder = Your_music_folder_path
            music = [music1, music2, music3, music4, music5]
            random_music = music_folder + random.choice(music) + '.mp3'
            os.system(random_music)
                 
            speak('Okay, here is your music! Enjoy!')
           

        else:
            query = query
            speak('Searching...')
            try:
                try:
                    res = client.query(query)
                    results = next(res.results).text
                    speak('WOLFRAM-ALPHA says - ')
                    speak('Got it.')
                    speak(results)
                   
                except:
                    results = wikipedia.summary(query, sentences=2)
                    speak('Got it.')
                    speak('WIKIPEDIA says - ')
                    speak(results)
       
            except:
                webbrowser.open('www.google.com')
       
        speak('Next Command! Sir!')

Traceback (most recent call last):
  File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: 'sapi5'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\abhis\Documents\sample.py", line 7, in <module>
    engine = pyttsx3.init('sapi5')
  File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\abhis\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\drivers\sapi5.py", line 10, in <module>
    import pythoncom
ModuleNotFoundError: No module named 'pythoncom'

Hii,

Try 

pip install pypiwin32 

or

$ pip3 install pypiwin32

Sometimes using pip3 also works if just pip is not working

​Could not find a version that satisfies the requirement pywin2 (from versions: )
No matching distribution found for pywin2

i am geeting this error after trying to download pywin2

Hello,

Try installing flask through the powershell using the following command.

pip install --isolated Flask

This will allow installation to avoid environment variables and user configuration.

and aslo If you are using a Python 3.5+ then you could add pypiwin32==223 to your requirements.txt file instead of pywin32

Hope it works!!
 

2 answers to this question.

0 votes

Hey, @ Ashmit,

Please try:
 

engine = pyttsx3.init('dummy') or engine = pyttsx.init('dummy')

Hope this Helps!!

To learn more, join the online course to do Masters in Python.

Thanks!

answered Apr 16, 2020 by Gitika
• 65,770 points
Yes I tried, it is throwing errors but not audible audio when i writing anything in say() function

Hi, @Babla,

Could you please what error you are facing? It will be easy for me to investigate further.

Thanks you so much
I can't hear anything when I write dummy inside init()

Hi, Myden,

Could you please elaborate on what you are trying to do?

I can't hear if we keep dummy inside unit()

Hi, @Bunny,

Are you facing any kind of error while executing your code snippet?

0 votes
even i faced the same problem ...just change the sapi5 to dummy and again change it back to sapi5 for windows
answered Jun 2, 2020 by anonymous

Related Questions In Python

+1 vote
3 answers
+2 votes
2 answers

ModuleNotFoundError: No module named 'pyttsx3

Hi@akhtar, To avoid this error you have to ...READ MORE

answered Apr 24, 2020 in Python by MD
• 95,460 points
29,081 views
0 votes
1 answer

ModuleNotFoundError: No module named 'pyttsx3'

Hello @SUHRID, For your query you can refer ...READ MORE

answered Oct 7, 2020 in Python by Niroj
• 82,840 points
1,598 views
0 votes
1 answer

how to solve the error : "ImportError: No module named Tkinter" in python.

Hi@Umama, If you are using Linux system, then ...READ MORE

answered Apr 27, 2020 in Python by MD
• 95,460 points
13,456 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,433 views
0 votes
1 answer
+5 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,790 points
4,066 views
+2 votes
3 answers

ModuleNotFoundError: No module named 'Crypto'

The module you’ve installed is different. To install ...READ MORE

answered Aug 20, 2019 in Python by Raman
81,000 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP