gpt4 book ai didi

python-3.x - Pyttsx3 不适用于 PyInstaller

转载 作者:行者123 更新时间:2023-12-04 00:30:59 29 4
gpt4 key购买 nike

我在使用 Pyttsx3 时从 PyInstaller 生成的 exe 中得到这个错误。该代码在 python 中运行良好。我试过使用其他版本的 PyInstaller 和 Pyttsx,但没有任何区别。我也试过 Py2exe,它也不能与 Pyttsx3 一起使用,有人知道是什么原因造成的吗?

The code

import pyttsx3 
engine = pyttsx3.init()

engine.say('Test')
engine.runAndWait()

The error after running the exe generated

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'

最佳答案

试试这个:

import pyttsx3
from pyttsx3.drivers import sapi5

engine = pyttsx3.init()
engine.say('Test')
engine.runAndWait()

解释:

您实际上需要从 pyttsx3 导入一个额外的模块。

关于python-3.x - Pyttsx3 不适用于 PyInstaller,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51024393/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com