如何解决名称未在python 3中定义的问题

时间:2018-06-24 15:48:51

标签: python-3.x

[在此处输入图片描述] [1] [如何解决名称未定义的问题,我正在使用python 3.6.5。我尝试使用全球性和更多技术

这是我的代码

import speech_recognition as sr
import pyttsx3

try:
    engine = pyttsx3.init()
except ImportError:
    print('Requested Driver Not Found')
except RuntimeError:
    print('Driver fails to initialize')

voices = engine.getProperty('voices')

for voice in voices:
    print(voice.id)

问题

"E:\Python projects\Dizzi\venv\Scripts\python.exe" "E:/Python projects/Dizzi/Dizzi.py"
Traceback (most recent call last):
Requested Driver Not Found
  File "E:/Python projects/Dizzi/Dizzi.py", line 12, in <module>
    voices = engine.getProperty('voices')
NameError: name 'engine' is not defined

] [2]

1 个答案:

答案 0 :(得分:0)

pyttsx3.init()失败,未找到请求的驱动程序。 变量引擎未创建。

您应该检查是否存在任何导入错误。