我正在尝试在python 3.7.4和pyttsx库中运行语音程序。但是在将文件从.py文件转换为.exe文件时,我遇到了很多问题。最初,在python中执行的程序运行良好。但是,当我使用pyinstaller将.py文件转换为.exe时,运行时会出现以下错误:
File "site-packages\pyttsx3\__init__.py", line 20, in init
File "c:\users\s som\appdata\local\programs\python\python37-32\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "DesktopAi.py", line 22, in <module>
File "site-packages\pyttsx3\__init__.py", line 22, in init
File "site-packages\pyttsx3\engine.py", line 30, in __init__
File "site-packages\pyttsx3\driver.py", line 50, in __init__
File "importlib\__init__.py", line 127, in import_module
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked
ModuleNotFoundError: No module named 'pyttsx3.drivers'
[11180] Failed to execute script DesktopAi ```
答案 0 :(得分:0)
您可以尝试以下操作:
pyinstaller --hidden-import=pyttsx3.drivers DesktopAi.py