在Windows上使用py2xe编译时出现了pyttsx的编译错误。

11

我使用了pyttsx库编写了一个Python应用程序。从tt.py文件中运行时,没有任何问题。我使用py2exe模块编译了这个tt.py文件。编译后,我尝试运行.exe文件,但出现了如图所示的错误。 enter image description here

我的setup.py文件如下:

from distutils.core import setup
import py2exe, sys, os
#includes =['drivers','drivers.sapi5'] #this tried. but making error 
sys.argv.append('py2exe')

setup(
    options = {'py2exe': {}},
    console=['tt.py'],

)

我使用了这个命令进行编译

python setup.py py2exe install

我正在tt.py中引入以下模块:

import pyttsx
import pyttsx.drivers.sapi5
import win32com
from time import sleep

我该如何修复这个问题?

2个回答

3

根据你的引入,你需要添加 import time

如果您的问题依然存在,使用 cx freeze 类似于 py to exe,并使用以下代码。

升级到 python 3.3 可能也是一个好主意。这可能会解决一些问题。

这篇文章可能有所帮助,它是关于你的错误的。 https://mail.python.org/pipermail/python-win32/2006-January/004184.html

import pyttsx
import pyttsx.drivers.sapi5
import win32com
from time import sleep
import sys
from cx_Freeze import setup, Executable

setup(
    name = "tt.py",
    version = "0.1",
    description = "your discription",
    executables = [Executable("The file name", base = "Win32GUI")])

这是 cx freeze 的链接 http://cx-freeze.sourceforge.net/

以下是使用说明的教程链接 http://cx-freeze.readthedocs.org/en/latest/overview.html


1

我尝试了几分钟的cx_Freeze,但当它没有立即工作时,我用py2exe试了一些其他方法,并使其成功运行:

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=['tt.py'], options = {'py2exe': py2exe_options})

请注意,这需要您在两台计算机上运行相同的版本(在本例中为v5.4)。如果您想规避此要求,则可能需要尝试更高级的方法。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接