He estado probando un script de asistente de IA personal de código abierto. El script funciona bien, pero quiero crear un ejecutable para poder regalárselo a uno de mis amigos. Sin embargo, cuando intento crear el ejecutable usando auto-py-to-exe, aparece el siguiente error:
Running auto-py-to-exe v2.10.1 Building directory: C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x Provided command: pyinstaller --noconfirm --onedir --console --no-embed-manifest "C:/Users/Tarun/AppData/Local/Programs/Python/Python310/AI_Ass.py" Recursion Limit is set to 5000 Executing: pyinstaller --noconfirm --onedir --console --no-embed-manifest C:/Users/Tarun/AppData/Local/Programs/Python/Python310/AI_Ass.py --distpath C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\application --workpath C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\build --specpath C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x 42681 INFO: PyInstaller: 4.6 42690 INFO: Python: 3.10.0 42732 INFO: Platform: Windows-10-10.0.19042-SP0 42744 INFO: wrote C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\AI_Ass.spec 42764 INFO: UPX is not available. 42772 INFO: Extending PYTHONPATH with paths ['C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310'] 43887 INFO: checking Analysis 43891 INFO: Building Analysis because Analysis-00.toc is non existent 43895 INFO: Initializing module dependency graph... 43915 INFO: Caching module graph hooks... 43975 INFO: Analyzing base_library.zip ... 54298 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'. 54306 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310\\lib' 57474 INFO: Caching module dependency graph... 58088 INFO: running Analysis Analysis-00.toc 58132 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable required by C:\Users\Tarun\AppData\Local\Programs\Python\Python310\python.exe 58365 INFO: Analyzing C:\Users\Tarun\AppData\Local\Programs\Python\Python310\AI_Ass.py 59641 INFO: Processing pre-safe import module hook urllib3.packages.six.moves from 'C:\\Users\\Tarun\\AppData\\Local\\Programs\\Python\\Python310\\lib\\site-packages\\PyInstaller\\hooks\\pre_safe_import_module\\hook-urllib3.packages.six.moves.py'. An error occurred while packaging Traceback (most recent call last): File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\auto_py_to_exe\packaging.py", line 131, in package run_pyinstaller() File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\__main__.py", line 124, in run run_build(pyi_config, spec_file, **vars(args)) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 782, in main build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build')) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 714, in build exec(code, spec_namespace) File "C:\Users\Tarun\AppData\Local\Temp\tmpjaw1ky1x\AI_Ass.spec", line 7, in <module> a = Analysis(['C:/Users/Tarun/AppData/Local/Programs/Python/Python310/AI_Ass.py'], File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 277, in __init__ self.__postinit__() File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\datastruct.py", line 155, in __postinit__ self.assemble() File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\building\build_main.py", line 439, in assemble priority_scripts.append(self.graph.add_script(script)) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 265, in add_script self._top_script_node = super().add_script(pathname) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1433, in add_script self._process_imports(n) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports target_module = self._safe_import_hook(*import_info, **kwargs)[0] File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module self._process_imports(n) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports target_module = self._safe_import_hook(*import_info, **kwargs)[0] File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module self._process_imports(n) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports target_module = self._safe_import_hook(*import_info, **kwargs)[0] File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module self._process_imports(n) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports target_module = self._safe_import_hook(*import_info, **kwargs)[0] File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1505, in import_hook target_package, target_module_partname = self._find_head_package( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1684, in _find_head_package target_package = self._safe_import_module( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module self._process_imports(n) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports target_module = self._safe_import_hook(*import_info, **kwargs)[0] File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook submodule = self._safe_import_module(head, mname, submodule) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module self._process_imports(n) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports target_module = self._safe_import_hook(*import_info, **kwargs)[0] File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook submodule = self._safe_import_module(head, mname, submodule) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2062, in _safe_import_module self._process_imports(n) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2850, in _process_imports target_module = self._safe_import_hook(*import_info, **kwargs)[0] File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2301, in _safe_import_hook target_modules = self.import_hook( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 1518, in import_hook submodule = self._safe_import_module(head, mname, submodule) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\depend\analysis.py", line 387, in _safe_import_module return super()._safe_import_module(module_basename, module_name, parent_package) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2061, in _safe_import_module n = self._scan_code(module, co, co_ast) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2645, in _scan_code self._scan_bytecode( File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\modulegraph.py", line 2749, in _scan_bytecode for inst in util.iterate_instructions(module_code_object): File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 147, in iterate_instructions yield from iterate_instructions(constant) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\site-packages\PyInstaller\lib\modulegraph\util.py", line 139, in iterate_instructions yield from get_instructions(code_object) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\dis.py", line 338, in _get_instructions_bytes argval, argrepr = _get_const_info(arg, constants) File "C:\Users\Tarun\AppData\Local\Programs\Python\Python310\lib\dis.py", line 292, in _get_const_info argval = const_list[const_index] IndexError: tuple index out of range Project output will not be moved to output folder Complete.Entiendo que ya hay un hilo sobre un problema similar, pero aún no resuelve el problema. Por eso busco ayuda
Realmente no tengo idea de por qué ocurre el error y cómo resolverlo. Estoy pegando el script a continuación para su referencia. ¿Puede ayudarme alguien, por favor? Gracias de antemano
#importing libraries import speech_recognition as sr import pyttsx3 import datetime import wikipedia import webbrowser import os import time import subprocess from ecapture import ecapture as ec import wolframalpha import json import requests #setting up speech engine engine=pyttsx3.init('sapi5') voices=engine.getProperty('voices') engine.setProperty('voice','voices[1].id') def speak(text): engine.say(text) engine.runAndWait() #Greet user def wishMe(): hour=datetime.datetime.now().hour if hour>=0 and hour<12: speak("Hello,Good Morning") print("Hello,Good Morning") elif hour>=12 and hour<18: speak("Hello,Good Afternoon") print("Hello,Good Afternoon") else: speak("Hello,Good Evening") print("Hello,Good Evening") #Setting up the command function for your AI assistant def takeCommand(): r=sr.Recognizer() with sr.Microphone() as source: print("Listening...") audio=r.listen(source) try: statement=r.recognize_google(audio,language='en-in') print(f"user said:{statement}\n") except Exception as e: speak("Pardon me, please say that again") return "None" return statement print("Loading your AI personal assistant Friday") speak("Loading your AI personal assistant Friday") wishMe() #main function if __name__=='__main__': while True: speak("Tell me how can I help you now?") statement = takeCommand().lower() if statement==0: continue if "good bye" in statement or "ok bye" in statement or "stop" in statement: speak('your personal assistant Friday is shutting down,Good bye') print('your personal assistant Friday is shutting down,Good bye') break if 'wikipedia' in statement: speak('Searching Wikipedia...') statement =statement.replace("wikipedia", "") results = wikipedia.summary(statement, sentences=10) webbrowser.open_new_tab("https://en.wikipedia.org/wiki/"+ statement) speak("According to Wikipedia") print(results) speak(results) elif 'open youtube' in statement: webbrowser.register('chrome', None, webbrowser.BackgroundBrowser("C://Program Files (x86)//Google//Chrome//Application//chrome.exe")) webbrowser.get('chrome').open_new_tab("https://www.youtube.com") #webbrowser.open_new_tab("https://www.youtube.com") speak("youtube is open now") time.sleep(5) elif 'open google' in statement: webbrowser.open_new_tab("https://www.google.com") speak("Google chrome is open now") time.sleep(5) elif 'open gmail' in statement: webbrowser.open_new_tab("gmail.com") speak("Google Mail open now") time.sleep(5) elif 'time' in statement: strTime=datetime.datetime.now().strftime("%H:%M:%S") speak(f"the time is {strTime}") elif 'news' in statement: news = webbrowser.open_new_tab("https://timesofindia.indiatimes.com/home/headlines") speak('Here are some headlines from the Times of India,Happy reading') time.sleep(6) elif "camera" in statement or "take a photo" in statement: ec.capture(0,"robo camera","img.jpg") elif 'search' in statement: statement = statement.replace("search", "") webbrowser.open_new_tab(statement) time.sleep(5) elif 'who are you' in statement or 'what can you do' in statement: speak('I am Friday version 1 point O your personal assistant. I am programmed to minor tasks like' 'opening youtube,google chrome, gmail and stackoverflow ,predict time,take a photo,search wikipedia,predict weather' 'In different cities, get top headline news from times of india and you can ask me computational or geographical questions too!') elif "who made you" in statement or "who created you" in statement or "who discovered you" in statement: speak("I was built by Mirthula") print("I was built by Mirthula") elif "log off" in statement or "sign out" in statement: speak("Ok , your pc will log off in 10 sec make sure you exit from all applications") subprocess.call(["shutdown", "/l"]) time.sleep(3)42681 INFO: PyInstaller: 4.6 42690 INFO: Python: 3.10.0Ahí está el problema. Python 3.10.0 tiene un error con PyInstaller 4.6. El problema no eres tú o PyInstaller. Intente convertirlo usando Python 3.9.7 en su lugar. Irónico, considerando que 3.10.0 se suponía que era una actualización de corrección de errores.
Python 3.10.2+ solucionará su problema. Si no puede esperar, agregue extended_arg = 0 a la línea 431 en el módulo dis.py como se ve a continuación.
https://github.com/python/cpython/commit/c5bfb88eb6f82111bb1603ae9d78d0476b552d66#
Si es como yo e instaló Python 3.10 desde una versión anterior, es posible que enfrente otros problemas debido a la instalación de paquetes a nivel de sistema y a nivel de usuario. Asegúrese de que los paquetes estén instalados en la ubicación prevista.
Este es un problema de Python 3.10. Para arreglarlo: Tienes que ir a la carpeta "Python310\Lib" y editar el archivo 'dis.py'. En el archivo 'dis.py' debe encontrar este "def _unpack_opargs" y dentro de la declaración else escriba una nueva línea con esto: "extended_arg = 0", luego guarde el archivo.
Hice algo así:
else: arg = None extended_arg = 0 yield (i, op, arg)y todo funciona bien ahora.
Encontré la solución aquí: https://bugs.python.org/issue45757 https://github.com/pyinstaller/pyinstaller/issues/6301
necesitas agregar
extended_arg = 0en la línea número 431 en el archivo Lib/dis.py, consulte https://github.com/python/cpython/commit/c5bfb88eb6f82111bb1603ae9d78d0476b552d66#