在使用 PyInstaller 对 PyQt 应用程序进行打包时,遇到了IndexError: tuple index out of range错误。错误信息显示在dis.py文件中,涉及_get_const_info方法,具体错误如下:
File "H:\MyGitProject\GUI\PyQt6\PyQt-Fluent-Widgets\PyQt\lib\dis.py", line 292, in _get_const_info argval = const_list[const_index] IndexError: tuple index out of range
当前 Python 版本为 3.10,PyInstaller 版本为 5.1。尽管 PyInstaller 官方文档表明已支持 3.7 及以上版本的 Python,但该错误仍然出现。
解决方案
问题的根源在于 PyInstaller 在 Python 3.10 及以上版本中解析字节码时出现的异常。解决方案是在python3\Lib\dis.py文件的_unpack_opargs(code)方法中添加extended_arg=0语句,以修正异常解析逻辑。
在dis.py文件中找到_unpack_opargs(code)函数,并修改如下:
def_unpack_opargs(code):extended_arg=0# 添加此行...修改后再次运行 PyInstaller 进行打包,即可成功完成编译,避免tuple index out of range错误的发生。