Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/351.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
我正在创建python文件的exe文件,但它总是崩溃。但它与python文件一样工作正常_Python_Python 3.x_Pyinstaller_Pyaudio - Fatal编程技术网

我正在创建python文件的exe文件,但它总是崩溃。但它与python文件一样工作正常

我正在创建python文件的exe文件,但它总是崩溃。但它与python文件一样工作正常,python,python-3.x,pyinstaller,pyaudio,Python,Python 3.x,Pyinstaller,Pyaudio,我正在使用pyinstaller创建Exe文件。它没有显示任何错误,但当我导出Exe文件时,它总是崩溃。但是它可以作为python文件正常工作,请帮助 这是exe文件转换的回溯 (aiEnv) PS E:\AI Creation> pyinstaller check.py 751 INFO: PyInstaller: 3.5 751 INFO: Python: 3.7.4 752 INFO: Platform: Windows-10-10.0.18362-S

我正在使用pyinstaller创建Exe文件。它没有显示任何错误,但当我导出Exe文件时,它总是崩溃。但是它可以作为python文件正常工作,请帮助

这是exe文件转换的回溯

    (aiEnv) PS E:\AI Creation> pyinstaller check.py
    751 INFO: PyInstaller: 3.5
    751 INFO: Python: 3.7.4
    752 INFO: Platform: Windows-10-10.0.18362-SP0
    785 INFO: wrote E:\AI Creation\check.spec
    786 INFO: UPX is not available.
    803 INFO: Extending PYTHONPATH with paths
    ['E:\\AI Creation', 'E:\\AI Creation']
    803 INFO: checking Analysis
    803 INFO: Building Analysis because Analysis-00.toc is non existent
    803 INFO: Initializing module dependency graph...
    809 INFO: Initializing module graph hooks...
    885 INFO: Analyzing base_library.zip ...
    6922 INFO: running Analysis Analysis-00.toc
    6940 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
      required by e:\ai creation\aienv\scripts\python.exe
    8121 INFO: Caching module hooks...
    8598 INFO: Analyzing E:\AI Creation\check.py
    9470 INFO: Processing pre-find module path hook   distutils
    9530 INFO: distutils: retargeting to non-venv dir 'c:\\users\\karti\\appdata\\local\\programs\\python\\python37\\Lib\\distutils\\__init__.py'
    9629 INFO: Processing pre-safe import module hook   six.moves
    17450 INFO: Processing pre-safe import module hook   urllib3.packages.six.moves
    19901 INFO: Processing pre-find module path hook   site
    19965 INFO: site: retargeting to fake-dir 'e:\\ai creation\\aienv\\lib\\site-packages\\PyInstaller\\fake-modules'
    21231 INFO: Processing pre-safe import module hook   setuptools.extern.six.moves
    25426 INFO: Loading module hooks...
    25427 INFO: Loading module hook "hook-certifi.py"...
    25441 INFO: Loading module hook "hook-encodings.py"...
    25540 INFO: Loading module hook "hook-httplib2.py"...
    25550 INFO: Loading module hook "hook-pkg_resources.py"...
    26110 INFO: Processing pre-safe import module hook   win32com
    26247 INFO: Loading module hook "hook-pycparser.py"...
    26275 INFO: Loading module hook "hook-pydoc.py"...
    26276 INFO: Loading module hook "hook-pythoncom.py"...
    26634 INFO: Loading module hook "hook-pywintypes.py"...
    26992 INFO: Loading module hook "hook-selenium.py"...
    27068 INFO: Loading module hook "hook-setuptools.py"...
    27409 WARNING: Hidden import "distutils.command.build_ext" not found!
    31666 INFO: Loading module hook "hook-speech_recognition.py"...
    31810 INFO: Loading module hook "hook-sysconfig.py"...
    31828 INFO: Loading module hook "hook-unidecode.py"...
    33771 INFO: Loading module hook "hook-win32com.py"...
    34846 INFO: Loading module hook "hook-xml.dom.domreg.py"...
    34852 INFO: Loading module hook "hook-xml.etree.cElementTree.py"...
    34853 INFO: Loading module hook "hook-xml.py"...
    34854 INFO: Loading module hook "hook-_tkinter.py"...
    35296 INFO: checking Tree
    35296 INFO: Building Tree because Tree-00.toc is non existent
    35298 INFO: Building Tree Tree-00.toc
    35418 INFO: checking Tree
    35418 INFO: Building Tree because Tree-01.toc is non existent
    35420 INFO: Building Tree Tree-01.toc
    35436 INFO: Loading module hook "hook-numpy.core.py"...
    37229 INFO: Loading module hook "hook-numpy.py"...
    37305 INFO: Looking for ctypes DLLs
    37353 INFO: Analyzing run-time hooks ...
    37361 INFO: Including run-time hook 'pyi_rth_certifi.py'
    37379 INFO: Including run-time hook 'pyi_rth_multiprocessing.py'
    37413 INFO: Including run-time hook 'pyi_rth_pkgres.py'
    37420 INFO: Including run-time hook 'pyi_rth_win32comgenpy.py'
    37428 INFO: Including run-time hook 'pyi_rth__tkinter.py'
    37449 INFO: Looking for dynamic libraries
    47405 INFO: Looking for eggs
    47406 INFO: Using Python library e:\ai creation\aienv\scripts\python37.dll
    47406 INFO: Found binding redirects:
    []
    47418 INFO: Warnings written to E:\AI Creation\build\check\warn-check.txt
    47568 INFO: Graph cross-reference written to E:\AI Creation\build\check\xref-check.html
    47701 INFO: checking PYZ
    47702 INFO: Building PYZ because PYZ-00.toc is non existent
    47703 INFO: Building PYZ (ZlibArchive) E:\AI Creation\build\check\PYZ-00.pyz
    49935 INFO: Building PYZ (ZlibArchive) E:\AI Creation\build\check\PYZ-00.pyz completed successfully.
    49968 INFO: checking PKG
    49969 INFO: Building PKG because PKG-00.toc is non existent
    49970 INFO: Building PKG (CArchive) PKG-00.pkg
    50049 INFO: Building PKG (CArchive) PKG-00.pkg completed successfully.
    50051 INFO: Bootloader e:\ai creation\aienv\lib\site-packages\PyInstaller\bootloader\Windows-64bit\run.exe
    50052 INFO: checking EXE
    50053 INFO: Building EXE because EXE-00.toc is non existent
    50056 INFO: Building EXE from EXE-00.toc
    50101 INFO: Appending archive to EXE E:\AI Creation\build\check\check.exe
    50187 INFO: Building EXE from EXE-00.toc completed successfully.
    50203 INFO: checking COLLECT
    50203 INFO: Building COLLECT because COLLECT-00.toc is non existent
    50205 INFO: Building COLLECT COLLECT-00.toc
    61880 INFO: Building COLLECT COLLECT-00.toc completed successfully.

这是我正在转换为exe文件的文件的代码。如果有任何错误或我缺少的东西,请告诉我。这里我使用的是pyttsx3库、语音识别库、日期时间库、维基百科库、webbrowser库、操作系统库和smtplib

这段代码的工作很简单,在这段代码中,我会说些什么,虚拟助手会根据我说的回答,我正在使用windows内置语音,我的windows中有4个语音

pyaudio或windows voice中是否存在任何问题请解释

import pyttsx3 #pip install pyttsx3
import speech_recognition as sr #pip install speechRecognition
import datetime
import wikipedia #pip install wikipedia
import webbrowser
import os
import smtplib

engine = pyttsx3.init('sapi5')
voices = engine.getProperty('voices')
print(voices)
engine.setProperty('rate', 135)     # setting up new voice rate
engine.setProperty('voice', voices[2].id)


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


def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning Sir,")

    elif hour>=12 and hour<18:
        speak("Good Afternoon Sir,")   

    else:
        speak("Good Evening Sir,")  

    speak(" My name is ashs")       

def takeCommand():
    #It takes microphone input from the user and returns string output

    r = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        r.pause_threshold = 0.8
        audio = r.listen(source)

    try:
        print("Recognizing...")    
        query = r.recognize_google(audio, language='en-in')
        print(f"User said: {query}\n")

    except Exception as e:
        # print(e)    
        print("Say that again please...")  
        return "None"
    return query

def sendEmail(to, content):
    server = smtplib.SMTP('smtp.gmail.com', 587)
    server.ehlo()
    server.starttls()
    server.login('youremail@gmail.com', 'your-password')
    server.sendmail('youremail@gmail.com', to, content)
    server.close()

if __name__ == "__main__":
    wishMe()
    while True:
    # if 1:
        query = takeCommand().lower()
        # Logic for executing tasks based on query
        if 'wikipedia' in query:
            speak('Searching Wikipedia...')
            query = query.replace("wikipedia", "")
            results = wikipedia.summary(query, sentences=2)
            speak("According to Wikipedia")
            print(results)
            speak(results)

        elif 'open youtube' in query:
            webbrowser.open("youtube.com")

        elif 'who created you' in query:
            speak("Kartik chauhan, created me on 7 august 2019")

        elif 'what is your age' in query:
            speak("Shut up! i cant tell you my age. dont ask me again")

        elif  'how old are you' in query:
            speak("Shut up! i cant tell you my age. dont ask me again")

        elif 'how are you' in query:
            speak("I am fine , what about you")

        elif 'i am good' in query:
            speak("nice! whats going on? can i help you?")

        elif 'pooja' in query:
            speak("you called me?")
            query = takeCommand().lower()
            if 'no' in query:
                speak("thanks for using me")
                exit
            elif 'yes' in query:
                speak("Ask me a question")
                exit
            else:
                speak('i cant  understand you.')
        elif 'open google' in query:
            webbrowser.open("google.com")

        elif 'open stackoverflow' in query:
            webbrowser.open("stackoverflow.com")  

        elif 'open facebook' in query:
            webbrowser.open("fb.com") 

        elif 'open Chrome' in query:
            music_dir = 'C:\Program Files (x86)\Google\Chrome\Application'
            if os.path.isdir("music_dir"):
                if len(music_dir) == 0:
                    speak("Sorry, But i cant find any music")
                else:   
                    if os.startfile(os.path.join(music_dir,'chrome.exe')):
                        speak("Here is your google chrome")
                    else:
                        speak("Cant open your browser")
            else:
                speak("There is no such directory")

        elif 'play music' in query:
            music_dir = 'D:\\Non Critical\\songs\\Favorite Songs2'
            if os.path.isdir("music_dir"):
                if len(music_dir) == 0:
                    speak("Sorry, But i cant find any music")
                else:
                    songs = os.listdir(music_dir)
                    print(songs)    
                    os.startfile(os.path.join(music_dir, songs[0]))
            else:
                speak("There is no such directory")

        elif 'the time' in query:
            strTime = datetime.datetime.now().strftime("%H:%M:%S")    
            speak(f"Sir, the time is {strTime}")

        elif 'open code' in query:
            codePath = "C:\\Users\\Haris\\AppData\\Local\\Programs\\Microsoft VS Code\\Code.exe"
            os.startfile(codePath)

        elif 'email to harry' in query:
            try:
                speak("What should I say?")
                content = takeCommand()
                to = "harryyourEmail@gmail.com"    
                sendEmail(to, content)
                speak("Email has been sent!")
            except Exception as e:
                print(e)
                speak("Sorry my friend harry bhai. I am not able to send this email")
        elif 'ok fine' in query:
            speak("Can i assist you in anything else?")
            query = takeCommand().lower()
            if 'no' in query:
                speak("thanks for using me")
                exit
            elif 'yes' in query:
                speak("Ask me a question")
                exit
导入pyttsx3#pip安装pyttsx3
将语音识别导入为sr#pip安装speechRecognition
导入日期时间
导入维基百科#pip安装维基百科
导入网络浏览器
导入操作系统
导入smtplib
engine=pyttsx3.init('sapi5')
voices=engine.getProperty('voices')
印刷品(声音)
engine.setProperty('rate',135)#设置新的语音速率
engine.setProperty('voice',voices[2].id)
def语音(音频):
引擎。比如说(音频)
engine.runAndWait()
def wishMe():
hour=int(datetime.datetime.now().hour)

如果小时>=0且小时=12且小时而不是
pyinstaller check.py
,则使用:

pyinstaller--hidden import=pyttsx3.drivers--hidden import=pyttsx3.drivers.dummy\
--隐藏导入=pyttsx3.drivers.espeak--隐藏导入=pyttsx3.drivers.nsss\
--hidden import=pyttsx3.drivers.sapi5--onefile check.py

Hi here,您是否使用了(-o,--onefile)和/或(-w,--windowed,--noconsole)等选项来编译它?不,没有添加任何注释。然后您可以添加执行的回溯吗?谢谢,但它不起作用。应用程序意外关闭。我认为它因麦克风而崩溃。我需要导入麦克风驱动程序吗?就像我对pyttsx3所做的一样?ModuleNotFoundError:没有名为'distutils'的模块