0

在 youtube 教程的帮助下,我一直在用 python 开发一个助手,类似于漫威电影中的 Jarvis。每次运行程序时,都会出现以下运行时错误:

RuntimeError: The current Numpy installation ('C:\\Python\\Python 3.9\\lib\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: 
    
Process finished with exit code 1

这是完整的追溯:

    "C:\Python\Python 3.9\python.exe" C:/M.A.R.T.I.N/martin.py
      File "C:\M.A.R.T.I.N\martin.py", line 6, in <module>
        engine = pyttsx3.init()
      File "C:\Python\Python 3.9\lib\site-packages\pyttsx3\__init__.py", line 22, in init
        eng = Engine(driverName, debug)
      File "C:\Python\Python 3.9\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
        self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
      File "C:\Python\Python 3.9\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
        self._module = importlib.import_module(name)
      File "C:\Python\Python 3.9\lib\importlib\__init__.py", line 127, in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
      File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
      File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
      File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
      File "<frozen importlib._bootstrap_external>", line 790, in exec_module
      File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
      File "C:\Python\Python 3.9\lib\site-packages\pyttsx3\drivers\sapi5.py", line 1, in <module>
        import comtypes.client  # Importing comtypes.client will make the gen subpackage
      File "C:\Python\Python 3.9\lib\site-packages\comtypes\__init__.py", line 1176, in <module>
        class IPersist(IUnknown):
      File "C:\Python\Python 3.9\lib\site-packages\comtypes\__init__.py", line 1180, in IPersist
        COMMETHOD([], HRESULT, 'GetClassID',
      File "C:\Python\Python 3.9\lib\site-packages\comtypes\__init__.py", line 1099, in COMMETHOD
        from comtypes.automation import VARIANT
      File "C:\Python\Python 3.9\lib\site-packages\comtypes\automation.py", line 12, in <module>
        from comtypes import npsupport
      File "C:\Python\Python 3.9\lib\site-packages\comtypes\npsupport.py", line 5, in <module>
        import numpy
      File "C:\Python\Python 3.9\lib\site-packages\numpy\__init__.py", line 305, in <module>
        _win_os_check()
      File "C:\Python\Python 3.9\lib\site-packages\numpy\__init__.py", line 302, in _win_os_check
        raise RuntimeError(msg.format(__file__)) from None
    RuntimeError: The current Numpy installation ('C:\\Python\\Python 3.9\\lib\\site-packages\\numpy\\__init__.py') fails to pass a sanity check due to a bug in the windows runtime. See this issue for more information: 
    
    Process finished with exit code 1

我不知道我犯了什么错误,但这是我的代码。

    import pyttsx3
    import datetime
    import speech_recognition as sr
    import webbrowser
    
    engine = pyttsx3.init()
    
    
    def speak(audio):
        engine.say(audio)
        engine.runAndWait()
    
    
    def time():
        Time = datetime.datetime.now().strftime("%I: %M: %S")
        speak(Time)
    
    
    def date():
        year = int(datetime.datetime.now().year)
        month = int(datetime.datetime.now().month)
        day = int(datetime.datetime.now().day)
        speak(day)
        speak(month)
        speak(year)
    
    
    def wishme():
        speak("Welcome back sir!")
        speak("How may I help you?")
    
    
    def takeCommand(ask):
        if ask:
            print(ask)
        r = sr.Recognizer()
        with sr.Microphone() as source:
            print("Listening...")
            r.pause_threshold = 1
            audio = r.listen(source)
            voice_data = ' '
    
        try:
            print("Recognizing...")
            voice_data = r.recognize_google(audio)
            print(voice_data)
    
        except Exception as e:
            print(e)
            speak("Say that again please sir...")
    
            return "none"
        return voice_data
    
    
    def respond(voice_data):
        if 'what is your name' in voice_data:
            speak("My name is MARTIN")
        if 'search' in voice_data:
            search = takeCommand(ask=speak('what do you want to search for?'))
            url = 'https://google.com/search?q=' + search
            webbrowser.get().open(url)
        if 'find location' in voice_data:
            location = takeCommand(ask=speak('what place do you want to search for?'))
            url = 'https://google.nl/maps/place/' + location
            webbrowser.get().open(url)
        if 'thank you' in voice_data:
            speak("You're welcome sir")
        if 'Martin not now' in voice_data:
            speak(" ")
        if 'exit' in voice_data:
            exit()
    
    
    
    
    wishme()
    
    voice_data = takeCommand(ask=True)
    respond(voice_data)

请让我知道我做错了什么。

4

1 回答 1

0

这里有一个线索:

RuntimeError: The current Numpy installation ('C:\Python\Python 3.9\lib\site-packages\numpy\init.py') fails to pass a sanity check due to a bug in the windows runtime.

您安装的 numpy 版本可能存在问题。

首先卸载numpy:

pip uninstall numpy

然后尝试您在此处看到的运行时错误的解决方案:

临时解决方案是使用 numpy 1.19.3。

pip install numpy==1.19.3

从此Microsoft 线程修复程序将在 2021 年 1 月左右提供

据我所知,您似乎是在 Python 3.9 中运行它,而不是在 a 中运行virtual environment它。建议使用虚拟环境来管理需要不同 Python 版本和依赖项/模块的项目。

于 2020-12-07T23:21:50.993 回答