0

I have been working using pyttsx3 on win7 64bit python 3.4.3. Everything is good with the .py script I made using pyttsx3 module (works fine alone).

The problem comes when I compile it with pyinstaller. I got an error saying "pyttsx3.drivers not found" and I fixed that by using a .spec file with hiddenimports. Then I got an error that says pywintypes.com_error:(-2147352573,member not found,none,none).

I found on github that someone by the name #natambashat fixed it by commenting out the pyi-rth-win32comgenpy.py runtime hook because that's only needed for pyttsx. But that didnt work for me, I still get the same error. Can you please help me?

Iain Duncan
  • 3,139
  • 2
  • 17
  • 28
Tom
  • 100
  • 8

2 Answers2

1

You cannot compile a script that contains pyttsx3 with pyinstaller because, pyinstaller like all compilers do not have every single python module. Here is a link that shows you all the compatible packages for pyinstaller.

Another option is py2exe. I am not a Windows user, so I don't know how to use it. But it supposedly supports pyttsx.

Another option though untested by me, is to download the pyttsx source code, put it into your project directory, import it in the code that uses pyttsx, then compile it with pyinstaller using:

pyinstaller --onefile app.py
xilpex
  • 3,097
  • 2
  • 14
  • 45
  • Thanks for the comment.But i added a hook-pyttsx3.py to the hooks folder.wouldn't that fix pyinstaller's limitations? And i did try py2exe but i get `Attribute error: no module named 'CLDIS` error. – Tom Feb 14 '19 at 22:45
  • By hook-pyttsx-3.py do you mean you downloaded the pyttsx source code and put it into your project folder (then imported the pyttsx in your project folder to the file that used pyttsx), then built it? – xilpex Feb 14 '19 at 22:51
  • no,i just got it from #natambashat on github.he just made a new script by copying and pasting all the things in hook-pyttsx and changed in the `hidden imports` to `hidden imports=[pyttsx3.drivers,pyttsx3.drivers.espeack,...(he added pyttsx3 before the dots)]`. Thanks,i will try the one u suggested,but would it exactly do? – Tom Feb 14 '19 at 23:05
  • It make pyinstaller think that pyttsx is part of the project source code, and intern compile your project with it. – xilpex Feb 14 '19 at 23:07
  • Ow...yeah,this seems a good idea.i will try it later(right now my friend is using my lap,but i sure will notify u later).Additionally,when i use the hook that i mentioned above,pyinstaller does this.it starts,goes to `importing hooks` and `......hook-xml,....,hook-pyttsx3,..`.(the dots represent other imports).so by this i am thinking maybe thats not the problem.The real problem is maybe the pywintypes.any suggestions regarding such kind of errors? – Tom Feb 14 '19 at 23:24
  • Thanks,really appreciate ur help.happy Valentine's day! – Tom Feb 14 '19 at 23:29
  • 1
    I tried what you said but that was the same as making a hook for pyttsx3,the same pywintypes error comes.But i fixed it doing the things i mentioned in my answer down here.Your "good luck" wish worked. – Tom Feb 15 '19 at 16:14
1

Eureka!!i fixed it! Am gonna write what i did step by step in case some one come-across to the same problem.

1.i made a hook-pyttsx3.py file and commented out the pyi-rth-win32comgenpy.py file(have a look at this link of github.( instead of commenting out,you can also remove the line "win32:pyi-rth-win32comgenpy.py" from the rthooks.DAT file in ...Lib/sitepackages/pyinstaller/loader/rthooks).

2.go to ...Lib/sitepackages/Win32com/client/dynamic.py and to the _GetDeskInvokeType function.Replace the last line(return invoke_type) with return varkind.

->For some people just step 1 works,but for me i need to apply step2.I found somewhere in sourceforge(i dont remember the link),when compiling a script that involves win32,pywin32 version 221 and 220 gives the pywintypes error i mentioned above.But pywin32 version 219 doesnt give this error(i am using pywin32 v221).And the reason behind that is,in the function i mentioned in step2,return invoke_type is only on version 221 and 220 but the return on v219 is return varkind.I don't know why this differece came if it gives such errors!

EDIT:This link Is better than the above i gave.

Tom
  • 100
  • 8