问题描述
我一直在尝试一个开源的个人 AI 助手脚本.该脚本工作正常,但我想创建一个可执行文件,以便我可以将可执行文件赠送给我的一位朋友.但是,当我尝试使用 auto-py-to-exe 创建可执行文件时,会出现以下错误:
I have been trying out an open-sourced personal AI assistant script. The script works fine but I want to create an executable so that I can gift the executable to one of my friends. However, when I try to create the executable using the auto-py-to-exe, it states the below error:
Running auto-py-to-exe v2.10.1
Building directory: C:UsersTarunAppDataLocalTemp mpjaw1ky1x
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:UsersTarunAppDataLocalTemp mpjaw1ky1xapplication --workpath C:UsersTarunAppDataLocalTemp mpjaw1ky1xuild --specpath C:UsersTarunAppDataLocalTemp mpjaw1ky1x
42681 INFO: PyInstaller: 4.6
42690 INFO: Python: 3.10.0
42732 INFO: Platform: Windows-10-10.0.19042-SP0
42744 INFO: wrote C:UsersTarunAppDataLocalTemp mpjaw1ky1xAI_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:UsersTarunAppDataLocalProgramsPythonPython310python.exe
58365 INFO: Analyzing C:UsersTarunAppDataLocalProgramsPythonPython310AI_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:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesauto_py_to_exepackaging.py", line 131, in package
run_pyinstaller()
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstaller\__main__.py", line 124, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstaller\__main__.py", line 58, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstalleruildinguild_main.py", line 782, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstalleruildinguild_main.py", line 714, in build
exec(code, spec_namespace)
File "C:UsersTarunAppDataLocalTemp mpjaw1ky1xAI_Ass.spec", line 7, in <module>
a = Analysis(['C:/Users/Tarun/AppData/Local/Programs/Python/Python310/AI_Ass.py'],
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstalleruildinguild_main.py", line 277, in __init__
self.__postinit__()
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstalleruildingdatastruct.py", line 155, in __postinit__
self.assemble()
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstalleruildinguild_main.py", line 439, in assemble
priority_scripts.append(self.graph.add_script(script))
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 265, in add_script
self._top_script_node = super().add_script(pathname)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1433, in add_script
self._process_imports(n)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2850, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2301, in _safe_import_hook
target_modules = self.import_hook(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1505, in import_hook
target_package, target_module_partname = self._find_head_package(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1684, in _find_head_package
target_package = self._safe_import_module(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 387, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2062, in _safe_import_module
self._process_imports(n)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2850, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2301, in _safe_import_hook
target_modules = self.import_hook(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1505, in import_hook
target_package, target_module_partname = self._find_head_package(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1684, in _find_head_package
target_package = self._safe_import_module(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 387, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2062, in _safe_import_module
self._process_imports(n)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2850, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2301, in _safe_import_hook
target_modules = self.import_hook(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1505, in import_hook
target_package, target_module_partname = self._find_head_package(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1684, in _find_head_package
target_package = self._safe_import_module(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 387, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2062, in _safe_import_module
self._process_imports(n)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2850, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2301, in _safe_import_hook
target_modules = self.import_hook(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1505, in import_hook
target_package, target_module_partname = self._find_head_package(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1684, in _find_head_package
target_package = self._safe_import_module(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 387, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2062, in _safe_import_module
self._process_imports(n)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2850, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2301, in _safe_import_hook
target_modules = self.import_hook(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1518, in import_hook
submodule = self._safe_import_module(head, mname, submodule)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 387, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2062, in _safe_import_module
self._process_imports(n)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2850, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2301, in _safe_import_hook
target_modules = self.import_hook(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1518, in import_hook
submodule = self._safe_import_module(head, mname, submodule)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 387, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2062, in _safe_import_module
self._process_imports(n)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2850, in _process_imports
target_module = self._safe_import_hook(*import_info, **kwargs)[0]
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2301, in _safe_import_hook
target_modules = self.import_hook(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 1518, in import_hook
submodule = self._safe_import_module(head, mname, submodule)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerdependanalysis.py", line 387, in _safe_import_module
return super()._safe_import_module(module_basename, module_name, parent_package)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2061, in _safe_import_module
n = self._scan_code(module, co, co_ast)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2645, in _scan_code
self._scan_bytecode(
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphmodulegraph.py", line 2749, in _scan_bytecode
for inst in util.iterate_instructions(module_code_object):
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphutil.py", line 147, in iterate_instructions
yield from iterate_instructions(constant)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libsite-packagesPyInstallerlibmodulegraphutil.py", line 139, in iterate_instructions
yield from get_instructions(code_object)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libdis.py", line 338, in _get_instructions_bytes
argval, argrepr = _get_const_info(arg, constants)
File "C:UsersTarunAppDataLocalProgramsPythonPython310libdis.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.
我知道已经有一个关于类似问题的帖子,但它仍然没有解决问题.因此寻求帮助
I understand that there is a thread already about similar issue but it still doesn't solve the issue. Hence seeking out help
我真的不知道为什么会发生错误以及如何解决它.我正在粘贴下面的脚本供您参考.有人可以帮忙吗?提前谢谢你
I really have no idea why is the error occurring and how to resolve it. I am pasting the script below for your reference. Can some one please help? Thank you in advance
#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}
")
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)
推荐答案
这是 Python 3.10 的问题.要解决这个问题:您必须转到文件夹Python310Lib";并编辑文件'dis.py'.在dis.py"文件中,你必须找到这个def _unpack_opargs".并在 else 语句中写入一个新行:extended_arg = 0",然后保存文件.
This is a Python 3.10 issue. To fix it: You have to go to the folder "Python310Lib" and edit the file 'dis.py'. In the 'dis.py' file you have to find this "def _unpack_opargs" and inside the else statement write a new line with this: "extended_arg = 0", then save the file.
我做了类似的事情:
else:
arg = None
extended_arg = 0
yield (i, op, arg)
现在一切正常.
我在这里找到了解决方案:https://bugs.python.org/issue45757https://github.com/pyinstaller/pyinstaller/issues/6301
I found the solution here: https://bugs.python.org/issue45757 https://github.com/pyinstaller/pyinstaller/issues/6301
这篇关于IndexError:当我尝试使用 auto-py-to-exe 从 python 脚本创建可执行文件时,元组索引超出范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!