pyttsx: No module named 'engine'
Asked Answered
P

9

27

I'm trying to install TTS package by using this. Everything was okay until I tried to execute the following command:

import pyttsx

I got back this error:

File "/usr/local/lib/python3.4/dist-packages/pyttsx/__init__.py", line 18, in module <br>
    from engine import Engine<br>
ImportError: No module named 'engine'

Any help would be appreciated. Thank you!

Pergrim answered 13/4, 2015 at 21:14 Comment(1)
Possible duplicate of import pyttsx works in python 2.7, but not in python3Guidebook
C
35

Guys there is an updated package compatible with Python3 :

pyttsx3

Works offline with no delay in the sound produced.

Installation:

pip install pyttsx3

Visit https://pyttsx3.readthedocs.io for the full usage docs. Thanks!

Christoffer answered 26/6, 2017 at 4:27 Comment(0)
P
19

Combining the advice from Jacob Tsui and Jokhongir Mamarasulov worked for me. To summarize:

In site_packages/pyttsx/init.py, modify "from engine import Engine" to

from .engine import Engine

Then, in site_packages/pyttsx/engine.py,

  1. Modify import driver to

    from . import driver
    
  2. Modify except Exception, e to

    except Exception as e
    

And finally, in site_packages/pyttsx/driver.py modify except Exception, e to

except Exception as e

See the responses from the aforementioned authors for the rationale behind these changes.

Pediment answered 29/10, 2016 at 19:32 Comment(2)
There is a fork of this project for Python3, found here: #41695604 This project seems to parallel the changes made above. However, on Mac, there is bug #1615148 after bug #1615148 after bug #41637733, so I'm bailing on implementing pyttsx on Mac, for now.Gangling
there will be a problem.. whenever u installed on another PC. user has to modify init.py file. But pip install pyttsx3 will do fine.Fond
P
8

I just had the same problem, try using pyttsx3 instead of pyttsx First install pyttsx3

pip install pyttsx3

and change the

import pyttsx

for

import pyttsx3

After that you have to change engine import (if you're using it in your main .py file). Use engineio instead. Install it

pip install python-engineio

then change import engine for import engineio and change your variables.

Here's an example

import pyttsx3
# import engineio #engineio module is not needed.

engineio = pyttsx3.init()
voices = engineio.getProperty('voices')
engineio.setProperty('rate', 130)    # Aquí puedes seleccionar la velocidad de la voz
engineio.setProperty('voice',voices[0].id)

def speak(text):
    engineio.say(text)
    engineio.runAndWait()

speak("What do you want me to say?")
while(1):
    phrase = input("--> ")
    if (phrase == "exit"):
        exit(0)
    speak(phrase)
    print(voices)

Hope this helps someone

Prompter answered 29/11, 2018 at 18:6 Comment(0)
C
7

For Python3, please install the latest version via pip3 install pyttsx3 and call import pyttsx3.

Capable answered 8/8, 2017 at 13:20 Comment(0)
P
5

I found out the solution. Library was created in python2 language and there are not a lot of differences between those 2 versions, but exclusively in this case that occurs.

Move to your DP folder and change in engine.py "except Exception as e" instead of "except Exception, e", line 67. Do the same in drive.py, line 105.

Because of files are secured try to execute, e. g.

sudo nano engine.py (or drive.py)

I guess I helped everyone with that kind of problem. :)

Pergrim answered 14/4, 2015 at 9:35 Comment(3)
This is not the solution, I did what you said and still same problem.Lithium
Same here.. This didn't solve the problem.. @Lithium what did you do? how to resolve this issue?Catamenia
GLHF - I have the same problem? what did you do?Herzig
S
5

Modify site_packages/pyttsx/init.py "from engine import Engine" to

from .engine import Engine

Modify site_packages/pyttsx/engine.py "import driver" to

from . import driver

Reason: The import statement "from engine import Engine" tells python to import Engine module from directory engine. In our case engine is not a directory, it's a python file, engine.py. So we need to tell python to import this engine module from current directory (".").

Stake answered 23/6, 2016 at 13:14 Comment(0)
M
2

I used this code after

pip install pywin32 pypiwin32 pyttsx3

and it worked perfectly for me

import os
import sys
import pyttsx3

engine = pyttsx3.init()
engine.say('hello world ')
engine.runAndWait()
Meteorite answered 3/7, 2018 at 16:41 Comment(0)
C
2

I had the same issue. First Try this command:

pip install pyttsx3

and then don't use

import pyttsx

use this

import pyttsx3

It will work.

Consubstantiate answered 1/5, 2021 at 10:15 Comment(0)
M
0

pyttsx: No module named 'engine'

File "/usr/local/lib/python3.4/dist-packages/pyttsx/__init__.py", line 18, in module <br>
    from engine import Engine<br>
ImportError: No module named 'engine'

If the above one is your error then try install pyttsx3 instead of pyttsx. Before installing check your python version, then download the version which is compatible to your python version.

Refer this link to get the previous versions of pyttsx3

REASON:

The reason we get the above error is because of the pyttsx3 version

which is not supported by your python version. Even if you get the error then

FOR pyttsx

Modify the init.py file located in C:\Users\YOUR USER\AppData\Local\Programs\Python\Python38-32\Lib\site_packages\pyttsx\init.py

Change

from engine import Engine

to

from .engine import Engine

pyttsx

Modify the engine.py file located at C:\Users\YOUR USER\AppData\Local\Programs\Python\Python38-32\Lib\site_packages\pyttsx\engine.py

Change

import driver

to

from . import driver

These are the two main solutions for the above error

Mitchiner answered 24/5, 2021 at 10:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.