我正在创建python文件的exe文件,但始终会崩溃。但它可以正常工作,如python文件

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

我正在使用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库,语音识别库,日期时间库,维基百科库,Web浏览器库,OS库和smtplib。

此代码的工作很简单,在该代码中,我会说些什么,虚拟助手会根据我说的内容进行答复,即我正在使用内置语音窗口,而我的窗口中有4种语音。

pyaudio或Windows语音是否有问题,请解释。

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('[email protected]', 'your-password')
    server.sendmail('[email protected]', 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 = "[email protected]"    
                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
python python-3.x pyinstaller pyaudio
1个回答
0
投票

代替pyinstaller check.py,使用:

pyinstaller --hidden-import=pyttsx3.drivers --hidden-import=pyttsx3.drivers.dummy \
   --hidden-import=pyttsx3.drivers.espeak --hidden-import=pyttsx3.drivers.nsss \
   --hidden-import=pyttsx3.drivers.sapi5 --onefile check.py
© www.soinside.com 2019 - 2024. All rights reserved.