Pyttsx: AttributeError: 'module' object ha

2019-09-14 18:33发布

Hi to everyone and thanks in advance

import pyttsx
engine = pyttsx.init()
engine.say('Hello World')
engine.runAndWait()

And I get this error:

Traceback (most recent call last):
  File "C:\Users\xxx\eclipse\workspace\Ai_Project\AI\Ai_Brain.py", line 8, in <module>
    engine = pyttsx.init()
AttributeError: 'module' object has no attribute 'init'

I am on Windows 7 using Python 2.7 and eclipse neon. Is this some kind of compatibility issue? I have searched a lot of related questions but applying the answers on my case didn't fix the error

2条回答
ら.Afraid
2楼-- · 2019-09-14 18:55

After importing the pyttsx module:

import pyttsx

use the command

dir(pyttsx)

Your output would be something as

['Engine',
 '__builtins__',
 '__doc__',
 '__file__',
 '__name__',
 '__package__',
 '__path__',
 '_activeEngines',
 'driver',
 'drivers',
 'engine',
 'init',
 'weakref']

(see 'init' in it near the end).

I guess your output will be different - it will reveal which module you actually imported regardless of its name pyttsx.

查看更多
The star\"
3楼-- · 2019-09-14 19:02

Fairly easy i guess and i post the answer in case someone in future has the same problem and every query he/she made didn't work. Consider this a human error and check your compatibility issues. In my case problem was that instead of pywin32-py2.7.exe i installed pywin32-219.win-amd64-py2.7.

Thanks to everyone who read or answered my question

查看更多
登录 后发表回答