以前曾问过这种类型的问题,但不是很有帮助。我在Windows 10 OS中使用版本Python3.6。我收到一个错误,KeyError:'sapi5'并且在处理上述异常期间,发生了另一个异常。 我的代码是-
import pyttsx3
engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices)
错误很大,但可能有助于解决问题-
Traceback (most recent call last):
File "C:\Users\utpal\AppData\Roaming\Python\Python36\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\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 "<input>", line 1, in <module>
File "C:\Users\utpal\AppData\Roaming\Python\Python36\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\utpal\AppData\Roaming\Python\Python36\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\utpal\AppData\Roaming\Python\Python36\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\importlib\__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "C:\Users\utpal\AppData\Roaming\Python\Python36\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
import win32com.client
File "C:\Program Files\JetBrains\PyCharm Community Edition 2018.3.3\helpers\pydev\_pydev_bundle\pydev_import_hook.py", line 21, in do_import
module = self._system_import(name, *args, **kwargs)
ModuleNotFoundError: No module named 'win32com'
我该怎么办?
答案 0 :(得分:2)
如果收到诸如
No module named win32com.client
,No module named win32
或No module named win32api
之类的错误,则需要另外安装pypiwin32
。