“回溯(最近一次调用最后一次):”如何在Python中删除此错误?

问题描述 投票:0回答:1

我正在用Python制作一个语音助手。我刚刚创建了它的第一个函数,但我一次又一次地遇到相同的回溯错误。谁能告诉我我在这里犯了什么错误?

这就是我创建的:

import pyttsx3
import speech_recognition
import pyaudio

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
# print(voices)
engine.setProperty('voice', voices[0].id)
engine.setProperty('rate', 170)


def speak(audio):
    engine.say(audio)
    engine.runAndWait()


def takecommand():
    r = speech_recognition.Recognizer()
    with speech_recognition.Microphone() as source:
        print("listening")
        r.pause_threshold = 1
        r.energy_threshold = 300
        audio = r.listen(source, 0, 4)

    try:
        print("understanding")
        query = r.recognize_google_cloud(audio, language="en-pk")
        print(f"u said{query}\n")
    except Exception as e:
        print("say that again")
        return "none"
    return query

if __name__ == "__main__":
    while True:
        query = takecommand().lower()
        if "wake up" in query:
            from greetme import greetMe

            greetMe()

            while True:
                query = takecommand().lower()
                if "go to sleep" in query:
                    speak("Ok sir, you can call me anytime")
                    break

但是我

Traceback (most recent call last):
  File "C:\Users\onean\PycharmProjects\jarvis\main.py", line 36, in <module>
    query = takecommand().lower()
            ^^^^^^^^^^^^^
  File "C:\Users\onean\PycharmProjects\jarvis\main.py", line 19, in takecommand
    with speech_recognition.Microphone() as source:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\onean\PycharmProjects\pythonProject1\venv\Lib\site-packages\speech_recognition\__init__.py", line 80, in __init__
    self.pyaudio_module = self.get_pyaudio()
                          ^^^^^^^^^^^^^^^^^^
  File "C:\Users\onean\PycharmProjects\pythonProject1\venv\Lib\site-packages\speech_recognition\__init__.py", line 111, in get_pyaudio
    from distutils.version import LooseVersion
ModuleNotFoundError: No module named 'distutils'

我一次又一次地遇到此错误,我在代码中找不到任何错误。我正在学习 python,所以我对这个错误没有太多了解

python traceback
1个回答
0
投票

尝试输入这个命令:

pip install setuptools distutils-pytest
© www.soinside.com 2019 - 2024. All rights reserved.