我从PyInstaller在使用Pyttsx3时生成的exe中得到这个错误。代码在python中工作得很好。我尝试过使用PyInstaller和Pyttsx的其他版本,但这并没有什么区别。我也尝试过Py2exe,它也不适用于Pyttsx3,有人知道是什么导致了这一点吗?
密码
import pyttsx3
engine = pyttsx3.init()
engine.say('Test')
engine.runAndWait()运行生成的exe后出现的错误。
Traceback (most recent call last):
File "site-packages\pyttsx3\__init__.py", line 44, in init
File "c:\python34\lib\weakref.py", line 125, in __getitem__
o = self.data[key]()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Test.py", line 85, in <module>
File "site-packages\pyttsx3\__init__.py", line 46, in init
File "site-packages\pyttsx3\engine.py", line 52, in __init__
File "site-packages\pyttsx3\driver.py", line 75, in __init__
File "importlib\__init__.py", line 109, in import_module
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2212, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 321, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 2254, in _gcd_import
File "<frozen importlib._bootstrap>", line 2237, in _find_and_load
File "<frozen importlib._bootstrap>", line 2224, in _find_and_load_unlocked
ImportError: No module named 'pyttsx3.drivers'发布于 2020-08-09 17:43:09
试试这个:
import pyttsx3
from pyttsx3.drivers import sapi5
engine = pyttsx3.init()
engine.say('Test')
engine.runAndWait()解释:
实际上,您需要从pyttsx3中导入一个额外的模块。
发布于 2020-08-16 21:11:29
Goto位置: C:\Users\username\AppData\Local\Programs\Python\Python38-32\Lib\site-packages\PyInstaller\hooks
创建一个新文件“钩子-pyttsx3.py”
内部文件,复制下面的代码。
#-----------------------------------------------------------------------------
# Copyright (c) 2013-2020, PyInstaller Development Team.
#
# Distributed under the terms of the GNU General Public License (version 2
# or later) with exception for distributing the bootloader.
#
# The full license is in the file COPYING.txt, distributed with this software.
#
# SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
#-----------------------------------------------------------------------------
""" pyttsx3 imports drivers module based on specific platform. Fount at https://github.com/nateshmbhat/pyttsx3/issues/6 """
hiddenimports = [
'pyttsx3.drivers',
'pyttsx3.drivers.dummy',
'pyttsx3.drivers.espeak',
'pyttsx3.drivers.nsss',
'pyttsx3.drivers.sapi5', ]现在,您的程序将运行没有错误。
点击这里创建Github问题
发布于 2019-03-02 09:46:19
试试这个:
pyinstaller --hidden-import=pyttsx3.drivers --hidden-import=pyttsx3.drivers.dummy --hidden-import=pyttsx3.drivers.espeak --hidden-import=pyttsx3.drivers.nsss --hidden-import=pyttsx3.drivers.sapi5隐藏的导入参数用于pyinstaller将第三方包导入到构建中.通过将上面的行添加到pyinstaller中,将创建一个带有隐藏-import=‘pyttsx3.river’、‘pyttsx3.drivers.dumy’的规范文件,.这将纠正错误“没有模块名为pyttsx.driver‘,但最终你将结束其他错误,我无法解决。
https://stackoverflow.com/questions/51024393
复制相似问题