简体   繁体   中英

Compiling error for python script to exe using py2exe and pyttsx

I have a python script that I made and it uses pyttsx for text to speech output. Whenever I converted it to an exe using py2exe and tried running the exe I get the following error:

Traceback (most recent call last):
  File "main.py", line 8, in <module>
  File "pyttsx\__init__.pyc", line 39, in init
  File "pyttsx\engine.pyc", line 45, in __init__
  File "pyttsx\driver.pyc", line 66, in __init__
  File "pyttsx\drivers\sapi5.pyc", line 37, in buildDriver
  File "pyttsx\drivers\sapi5.pyc", line 46, in __init__
  File "win32com\client\__init__.pyc", line 317, in WithEv
AttributeError: 'NoneType' object has no attribute 'CLSID'

Here is a copy of my setup.py:

from distutils.core import setup
import py2exe

setup(
    console=['main.py'],
    options = {
        "py2exe":{
            "includes":[
                'pyttsx.drivers.sapi5'
            ]
        }
    }
)

YEY - I got it working!

from distutils.core import setup
import py2exe

py2exe_options = { 'includes': ['pyttsx.drivers.sapi5', 'win32com.gen_py.C866CA3A-32F7-11D2-9602-00C04F8EE628x0x5x4'],
                   'typelibs': [('{C866CA3A-32F7-11D2-9602-00C04F8EE628}', 0, 5, 4)] }

setup(console=['main.py'], options = {'py2exe': py2exe_options})

Note though that this requires you to run the same version (v5.4 in my case) on both machines. If you want to circumvent that you probably need to try something more advanced .

You should try running with pyttsx3 and use your system's text to speech api like sapi 5 for windows. Its much faster and more recent.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM