2017-12-27 91 views
2

pythonで実行しているこのファイルを使用すると、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() 

をループする方法はありますかそれは声は私がループ上でプログラムを使用することができるようにするために有効でなければならないことですか?唯一のループはボイスレコグナイザですか?私は実行可能ファイルを実行しようとすると、私はこのエラーコードを取得しますが、PYスクリプトでだから私はここに

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ファイルの変換で何かの腐敗を感じ、それが正常に実行さ形成:あなたの考えてくれ

NOTEを与えます要求されたとして.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を使用することができます。このspecファイルに対して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ファイルを実行します。 pyinstallerの最新バージョンをrepoからインストールしてください: 'pip install -U git + https:// github.com/pyinstaller/pyinstaller.git' – 9dogs

+0

アップデート方法はありますか?pip install --upgrade pyinstaller –

関連する問題