0

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

e4c5
  • 52,766
  • 11
  • 101
  • 134
Jim Noulis
  • 13
  • 3
  • 6
  • 2
    Do you have a pyttsx.py in your work dir? – gushitong May 11 '17 at 11:21
  • By that you mean in my workspace folder? No there i have 2 files _init_.py and AI_Brain.py. If you mean whether i installed pyttsx in my python installation , it is a yes. – Jim Noulis May 11 '17 at 12:18

2 Answers2

0

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.

MarianD
  • 13,096
  • 12
  • 42
  • 54
  • Where should i use the command? In the eclipse code? If yes it didn't show me anything(just blank). – Jim Noulis May 11 '17 at 12:16
  • There are 2 possibilities, I meant the first: **1)** In the *PyDev console* - probably right bottom part of your Eclipse IDE with "Console" tab. From the last icon (with a tooltip Open Console) choose "PyDev Console). **2)** In the *Eclipse editor*, as you did, but then you have to use `print` command: `print dir(pyttsx)` – MarianD May 12 '17 at 06:25
0

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

Jim Noulis
  • 13
  • 3
  • 6