2017-12-27 56 views
2

이 파일을 파이썬에서 사용할 때 pyinstaller를 사용하여 실행 파일로 변환하면 무한한 시간 동안 실행됩니다. 눈 깜박임을 위해서만 실행되고 너무 빨리 실행됩니다. 그것을보십시오. 당신은 나에게 설명과 해결책을 줄 수 있니? 그것은 음성이 나를 루프에서 프로그램을 사용할 수 있도록 순서를 활성화하는 것을왜 exe로 변환 한 후 pyttsx3 오류가 발생합니까?

import speech_recognition as sr 
import pyttsx3 
import pocketsphinx 
import pyaudio 
import random 
import os 
import wikipedia 
import time 





engine = pyttsx3.init() 
def talktome(text): 
    engine.say(text) 
    engine.runAndWait() 
#default start up 
talktome('Caios is now online ronald,sir') 
talktome('how can i assist you') 


#main function contaning all commands 
def mainfunction(): 
    a=r.listen(source) 
    user= r.recognize_sphinx(a) 
    print(user) 


         #main commands 

    numb_of_times = 0 

    #greetings recognition  
    if user == 'hello' or user == 'wassup' or user == 'hi' or user == 'hows it going': 
     numb_of_times +=1 
     #checking to see if the number of times greeted is more than 2 
     #adding a little personality to caios 
     if numb_of_times > 2 : 
      z='still here sir' , 'how many times are you going to greet me sir' 
      n = random.choice(z) 
      talktome(n) 


     a = 'Hi ,Sir how are you doing today?' , 'how is it going ,sir' 
     k = random.choice(a) 

     talktome(k) 
    #Unpleasant greetings recognition 
    elif user == 'bitch' or user == 'whore' or user == 'hoe' or user == 'slut' or user == 'pussy': 
    k = 'just a tip , Caios doesnt respond to ignorace', 'thats not nice , do you talk to your parents with that tone' 
    A= random.choice(k) 
    talktome(A) 





    else: 
     print('unknown command of C.A.I.O.S') 
     print('        ') 




#speech recognition function/if statement - 
if __name__ == "__main__":       
    r = sr.Recognizer() 
    with sr.Microphone() as source: 
     while 3: 
      mainfunction() 

통해 반복하는 방법이 아니면 무엇입니까? 유일한 루프가 음성 인식기이기 때문에? 내가 실행 파일을 실행하려고하면이 오류 코드를 얻을 수 있지만, 평 스크립트 그래서 내가 여기

file.exe                   

Traceback (most recent call last): 
File "site-packages\pyttsx3\__init__.py", line 44, in init 
File "c:\users\kxrk\appdata\local\programs\python\python36-32\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 "testfile.py", line 14, in <module> 
     File "site-packages\pyttsx3\__init__.py", line 46, in init 
     File "site-packages\pyttsx3\engine.py", line 52, in __init__ 
     File "site-packages\pyttsx3\driver.py", line 75, in __init__   
     File "importlib\__init__.py", line 126, in import_module 
     File "<frozen importlib._bootstrap>", line 994, in _gcd_import 
     File "<frozen importlib._bootstrap>", line 971, in _find_and_load 
     File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked 
     File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed 
     File "<frozen importlib._bootstrap>", line 994, in _gcd_import 
     File "<frozen importlib._bootstrap>", line 971, in _find_and_load 
     File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked 
    ModuleNotFoundError: No module named 'pyttsx3.drivers' 
[2768] Failed to execute script testfile 

인 EXE 변환 뭔가 부패를 느낄 정상적으로 실행 형성 : 당신의 생각 날

참고주세요 요청에 따라을 .spec 파일 :

# -*- mode: python -*- 

block_cipher = None 


a = Analysis(['testfile.py'], 
      pathex=['C:\\Users\\Kxrk\\AppData\\Local\\Programs\\Python\\Python36-32\\Scripts'], 
      binaries=[], 
      datas=[], 
      hiddenimports=[], 
      hookspath=[], 
      runtime_hooks=[], 
      excludes=[], 
      win_no_prefer_redirects=False, 
      win_private_assemblies=False, 
      cipher=block_cipher) 
pyz = PYZ(a.pure, a.zipped_data, 
      cipher=block_cipher) 
exe = EXE(pyz, 
      a.scripts, 
      exclude_binaries=True, 
      name='testfile', 
      debug=False, 
      strip=False, 
      upx=True, 
      console=True) 
coll = COLLECT(exe, 
       a.binaries, 
       a.zipfiles, 
       a.datas, 
       strip=False, 
       upx=True, 
       name='testfile') 
+1

pyinstaller testfile.spec이 아마도 당신이 프로그램이 전혀 시작되지 않습니다, 그것은 오류를 출력하고 종료. 명령 행 (cmd)에서 exe-file을 실행하여 실제 결과를 확인하십시오. – 9dogs

+0

나는 오류 메시지 –

+0

을 포함하여 질문을 편집했습니다. 예,'pyttsx3.drivers' 모듈이 exe-file에 번들되지 않았습니다. 질문에 pyinstaller가 생성 한 .spec 파일을 포함 시키십시오. – 9dogs

답변

1

당신은 분배에 pyttsx3의 모든 서브 모듈을 번들로 pyInstaller 중에 모듈에서 collect_submodules를 사용할 수 있습니다. 이 사양 파일에 대해 PyInstaller를 실행하여

# -*- mode: python -*- 
from PyInstaller.utils.hooks import collect_submodules 


block_cipher = None 
hidden_imports = collect_submodules('pyttsx3') 


a = Analysis(['testfile.py'], 
      pathex=['C:\\Users\\Kxrk\\AppData\\Local\\Programs\\Python\\Python36-32\\Scripts'], 
      binaries=[], 
      datas=[], 
      hiddenimports=hidden_imports, 
      hookspath=[], 
      runtime_hooks=[], 
      excludes=[], 
      win_no_prefer_redirects=False, 
      win_private_assemblies=False, 
      cipher=block_cipher) 
pyz = PYZ(a.pure, a.zipped_data, 
      cipher=block_cipher) 
exe = EXE(pyz, 
      a.scripts, 
      exclude_binaries=True, 
      name='sr', 
      debug=False, 
      strip=False, 
      upx=True, 
      console=True) 
coll = COLLECT(exe, 
       a.binaries, 
       a.zipfiles, 
       a.datas, 
       strip=False, 
       upx=True, 
       name='sr') 

빌드 : 다음 사양 파일을보십시오

+0

수정 후 동일한 오류 –

+0

여전히 작동하지 않습니다. 이상합니다. 나는 그것을 테스트하고 성공적으로 exe 파일을 실행합니다. Repo에서 최신 버전의 pyinstaller를 설치하십시오 :'pip install -U git + https : // github.com/pyinstaller/pyinstaller.git' – 9dogs

+0

업데이트 방법이 있습니까? pip install --upgrade pyinstaller –