IndexError: tuple index out of range when I try to create an executable from a python script using auto-py-to-exe

IndexError: tuple index out of range when I try to create an executable from a python script using auto-py-to-exe

我一直在试用一个开源的个人 AI 助手脚本。该脚本工作正常,但我想创建一个可执行文件,以便我可以将该可执行文件赠送给我的一位朋友。但是,当我尝试使用 auto-py-to-exe 创建可执行文件时,它指出以下错误:

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.

我知道已经有关于类似问题的帖子,但它仍然没有解决问题。因此寻求帮助

我真的不知道为什么会出现错误以及如何解决它。我正在粘贴下面的脚本供您参考。有人可以帮忙吗?提前谢谢你

#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 Whosebug ,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.0

有问题。 Python 3.10.0 在 PyInstaller 4.6 中存在错误。问题不在于您或 PyInstaller。尝试使用 Python 3.9.7 来转换它。具有讽刺意味的是,考虑到 3.10.0 应该是错误修复更新。

Python 3.10.2+ 将解决您的问题。如果您等不及了,请将 extended_arg = 0 添加到 dis.py 模块的第 431 行,如下所示。

https://github.com/python/cpython/commit/c5bfb88eb6f82111bb1603ae9d78d0476b552d66#

如果您像我一样从旧版本安装了 Python 3.10,由于在系统级别和用户级别安装软件包,您可能会遇到一些其他问题。确保软件包安装到预期位置。

这是一个 Python 3.10 问题。 要解决这个问题: 您必须转到文件夹“Python310\Lib”并编辑文件 'dis.py'。 在 'dis.py' 文件中,您必须找到这个“def _unpack_opargs”,并在 else 语句中写一个新行:“extended_arg = 0”,然后保存文件。

我做了类似的事情:

else:
    arg = None
    extended_arg = 0 
yield (i, op, arg)

现在一切正常。

我在这里找到了解决方案: https://bugs.python.org/issue45757 https://github.com/pyinstaller/pyinstaller/issues/6301

你需要添加

extended_arg = 0

Lib/dis.py 文件中的第 431 行 请参考 https://github.com/python/cpython/commit/c5bfb88eb6f82111bb1603ae9d78d0476b552d66#