首先,我用:
我正在尝试使用pyttsx3,但是我无法用官方代码示例来初始化它。
import pyttsx3
engine = pyttsx3.init()
engine.say('Just a sample text.')
engine.runAndWait()第二行给出了一个错误:
AttributeError:模块'pyttsx3‘没有属性'init’
我用PIP安装了它:
pip install pyttsx3我试着修复它安装pypiwin32,但它仍然不能工作:
pip install pypiwin32当我执行以下脚本时:
import pyttsx3
print(dir(pyttsx3))我明白了:
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'pyttsx3']以下内容如下:
drivers (folder)
__pycache__ (folder)
driver.py
engine.py
six.py
voice.py
__init__.pyAt:
C:\Program Files\Python36\Lib\site-packages\pyttsx3以及文件__init__.py的内容(我省略了注释):
from .engine import Engine
import weakref
_activeEngines = weakref.WeakValueDictionary()
def init(driverName=None, debug=False):
try:
eng = _activeEngines[driverName]
except KeyError:
eng = Engine(driverName, debug)
_activeEngines[driverName] = eng
return eng发布于 2017-10-21 14:18:38
似乎模块pyttsx3未被正确初始化。我希望在模块路径中没有一个名为pyttsx3.py的文件。我发现了一个相关的问题,这里。
https://stackoverflow.com/questions/46863651
复制相似问题