Python 我无法运行此.py文件。他犯了许多错误。不能';我想不出是什么';发生什么事了

Python 我无法运行此.py文件。他犯了许多错误。不能';我想不出是什么';发生什么事了,python,Python,航站楼给出: import speech_recognition as sr import pyttsx3 import pywhatkit import datetime import wikipedia import pyjokes listener = sr.Recognizer() engine = pyttsx3.init() voices = engine.getProperty('voices') engine.setProperty('voice', voices[0].id)

航站楼给出:

import speech_recognition as sr
import pyttsx3
import pywhatkit
import datetime
import wikipedia
import pyjokes

listener = sr.Recognizer()
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id)


def talk(text):
  engine.say(text)
  engine.runAndWait()


 def take_command():
try:
    with sr.Microphone() as source:
        print('listening...')
        voice = listener.listen(source)
        command = listener.recognize_google(voice)
        command = command.lower()
        if 'cyther' in command:
            command = command.replace('cyther', '')
            print(command)
except:
    pass
return command


def run_alexa():
  command = take_command()
  print(command)
  if 'play' in command:
      song = command.replace('play', '')
      talk('playing ' + song)
      pywhatkit.playonyt(song)
elif 'time' in command:
    time = datetime.datetime.now().strftime('%I:%M %p')
    talk('Current time is ' + time)
elif 'who the heck is' in command:
    person = command.replace('who the heck is', '')
    info = wikipedia.summary(person, 1)
    print(info)
    talk(info)
elif 'date' in command:
    talk('sorry, I have a headache')
elif 'are you single' in command:
    talk('I am in a relationship with wifi')
elif 'joke' in command:
    talk(pyjokes.get_joke())
else:
    talk('Please say the command again.')


while True:
  run_alexa()
C:\Users\Prakash\Desktop\romatic alexa main>C:/Users/Prakash/AppData/Local/Programs/Python/Python37/Python.exe C:/Users/Prakash/Desktop/romatic alexa main/main.py
回溯(最近一次呼叫最后一次):
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\pyttsx3\\uuuu init\uuu.py”,第20行,在init中
eng=\u活动引擎[driverName]
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\weakref.py”,第137行,在\uu getitem中__
o=自身数据[键]()
KeyError:无
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\pyttsx3\drivers\sapi5.py”,第3行,在
从comtypes.gen导入SpeechLib#comtypes
ImportError:无法从“comtypes.gen”(C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\comtypes\gen\\uuuuu init\uuuuu.py)导入名称“SpeechLib”
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
WINFUNCTYPE中的文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\ctypes\\uuuuu init\uuuu.py”,第121行
return\u win\u functype\u cache[(restype,argtypes,flags)]
KeyError:(,(,),0)
在处理上述异常期间,发生了另一个异常:
回溯(最近一次呼叫最后一次):
文件“c:/Users/Prakash/Desktop/alexa main/main.py”,第9行,在
engine=pyttsx3.init()
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\pyttsx3\\uuuu init\uuu.py”,第22行,在init中
eng=引擎(驱动器名称,调试)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\pyttsx3\engine.py”,第30行,在\uuu init中__
self.proxy=driver.DriverProxy(weakref.proxy(self)、driverName、debug)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\pyttsx3\driver.py”,第50行,在__
self.\u模块=导入lib.import\u模块(名称)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\importlib\\uuuuu init\uuuuu.py”,第127行,在导入模块中
return _bootstrap._gcd_import(名称[级别:],包,级别)
文件“”,第1006行,在\u gcd\u导入中
文件“”,第983行,在_find_和_load中
文件“”,第967行,在“查找”和“加载”中解锁
文件“”,第677行,在\u加载\u解锁
exec_模块中第728行的文件“”
文件“”,第219行,在“调用”中,删除了“帧”
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\pyttsx3\drivers\sapi5.py”,第6行,在
engine=comtypes.client.CreateObject(“SAPI.SpVoice”)
CreateObject中的文件“C:\Users\Prakash\AppData\Local\Programs\Python\37\lib\site packages\comtypes\client\\uuuuu init\uuuuuu.py”,第250行
返回管理(obj,clsid,接口=接口)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\comtypes\client\ \uuuuuu init\uuuuuuu.py”,第188行,在\u manage中
obj=GetBestInterface(obj)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\comtypes\client\ \uuuuu init\uuuuuu.py”,第110行,在GetBestInterface中
mod=GetModule(tlib)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\comtypes\client\\u generate.py”,第118行,在GetModule中
mod=\u CreateWrapper(tlib,路径名)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\37\lib\site packages\comtypes\client\\u generate.py”,第198行,在CreateWrapper中
mod=\u我的\u导入(全名)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\37\lib\site packages\comtypes\client\\u generate.py”,第19行,在“我的导入”中
return uuu import uuuuu(全名,globals(),locals(),['DUMMY']))
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\comtypes\gen\\u C866CA3A\u 32F7\u 11D2\u 9602\u 00C04F8EE628\u 0\u 5\u 4.py”,第253行,in
(['out','retval',指针(变量),'NewPosition'),
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\comtypes\\uuuuuuuu init\uuuuuuuuu.py”,第323行,位于\uuuu setattr中__
自我制作方法(值)
文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site packages\comtypes\\uuuuuuuu init\uuuuuuuuuu.py”,第692行,在\u make\u方法中
prototype=WINFUNCTYPE(重新类型,*argtypes)
WINFUNCTYPE中的文件“C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\ctypes\\uuuuuu init\uuuuuu.py”,第123行
类WinFunctionType(\u CFuncPtr):
TypeError:_argtypes_中的项1通过值传递union,这是不受支持的。
有人知道发生了什么吗?
只是随机看到这个项目,然后开始输入相同的内容。已导入所需的所有模块,但我遇到了此错误。

您在此处执行的错误之一是:

第一:如果command==“cyther”,您应该使用(例如在代码中)
if:
做任何你想做的事情这应该是你代码中所有if和elif语句的格式(替换为:
if命令在“示例”:
-->到
if命令==“示例”:

我对
run_alexa()
函数中的任何内容都不熟悉,但是上面提到的东西应该可以解决您的大部分问题


希望这对您有所帮助,您可以随意提出任何与此相关的问题:)

代码没有正确缩进。另外,这个问题与stackoverflow无关。如果您有特定问题,我们可能会提供帮助,但修复程序中的所有错误并不是stackoverflow的真正目的。您需要一个解决方案。目前有太多不相关的代码。不管怎样,它可能是。
C:\Users\Prakash\Desktop\romantic-alexa-main>C:/Users/Prakash/AppData/Local/Programs/Python/Python37/python.exe c:/Users/Prakash/Desktop/romantic-alexa-main/main.py
Traceback (most recent call last):
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
    from comtypes.gen import SpeechLib  # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\gen\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 121, in WINFUNCTYPE
    return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.wintypes.LP_c_long'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:/Users/Prakash/Desktop/romantic-alexa-main/main.py", line 9, in <module>
    engine = pyttsx3.init()
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
    engine = comtypes.client.CreateObject("SAPI.SpVoice")
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
    return _manage(obj, clsid, interface=interface)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
    obj = GetBestInterface(obj)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface
    mod = GetModule(tlib)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 118, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 198, in _CreateWrapper
    mod = _my_import(fullname)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\client\_generate.py", line 19, in _my_import
    return __import__(fullname, globals(), locals(), ['DUMMY'])
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 253, in <module>
    ( ['out', 'retval'], POINTER(VARIANT), 'NewPosition' )),
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\__init__.py", line 323, in __setattr__
    self._make_methods(value)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\site-packages\comtypes\__init__.py", line 692, in _make_methods
    prototype = WINFUNCTYPE(restype, *argtypes)
  File "C:\Users\Prakash\AppData\Local\Programs\Python\Python37\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
    class WinFunctionType(_CFuncPtr):
TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.