Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
485 views
in Technique[技术] by (71.8m points)

python - Error building executable with cx_Freeze: IndexError: tuple index out of range

Background

I have made a program that I am trying to turn into an executable using CX_Freeze. The setup.py file is placed inside the same directory as all files I am working with. I don't use any extra libraries other than TKinter and OS.

The program works perfectly fine normally when I run it via PyCharm>Run


Version Numbers

  • cx_Freeze ver: - 5.0
  • cx_Freeze .whl: - cx_Freeze-5.0-cp36-cp36m-win_amd64.whl
  • python ver: - 3.6.0b4
  • pycharm ver: - 2016.3.1

This is my setup.py file

import cx_Freeze
import sys
from cx_Freeze import setup, Executable


base = None

if sys.platform == 'win32':
    base = "Win32GUI"

cx_Freeze.setup(
    name = "FileOrganizer-Client",
    options = {"build_exe": {"packages":["tkinter","os"],"include_files":["icon2.ico"]}},
    version = "0.01",
    description = "File Organizer",
    executables = [cx_Freeze.Executable("alpha_GUI.py", base=base, icon="icon2.ico")]
)

This is the error I get when I run "python setup.py build" inside the directory

C:UsersJeremyPycharmProjectscleanup>C:UsersJeremyAppDataLocalProgramsPythonPython36python setup.py build running build running build_exe
Traceback (most recent call last):   File "setup.py", line 18, in
<module>
    executables = [cx_Freeze.Executable("alpha_GUI.py", base=base, icon="icon2.ico")]

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezedist.py",
line 349, in setup
    distutils.core.setup(**attrs)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libdistutilscore.py",
line 148, in setup
    dist.run_commands()

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libdistutilsdist.py",
line 955, in run_commands
    self.run_command(cmd)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libdistutilsdist.py",
line 974, in run_command
    cmd_obj.run()

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libdistutilscommanduild.py",
line 135, in run
    self.run_command(cmd_name)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libdistutilscmd.py",
line 313, in run_command
    self.distribution.run_command(command)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libdistutilsdist.py",
line 974, in run_command
    cmd_obj.run()

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezedist.py",
line 219, in run
    freezer.Freeze()

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefreezer.py",
line 621, in Freeze
    self.finder = self._GetModuleFinder()

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefreezer.py",
line 333, in _GetModuleFinder
    self.path, self.replacePaths)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefinder.py",
line 150, in __init__
    self._AddBaseModules()

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefinder.py",
line 161, in _AddBaseModules
    self.IncludeModule("traceback")

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefinder.py",
line 651, in IncludeModule
    namespace = namespace)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefinder.py",
line 310, in _ImportModule
    deferredImports, namespace = namespace)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefinder.py",
line 403, in _InternalImportModule
    parentModule, namespace)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefinder.py",
line 474, in _LoadModule
    self._ScanCode(module.code, module, deferredImports)

  File
"C:UsersJeremyAppDataLocalProgramsPythonPython36libsite-packagescx_Freezefinder.py",
line 562, in _ScanCode
    arguments.append(co.co_consts[opArg])

IndexError: tuple index out of range

I am not very skilled or familiar with any of this so I hope I didn't leave anything out. Please let me know if any more information is needed.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This has been submitted as a bug in cx_freeze, Python 3.6 has introduced some changes to code objects (most notably with PEP 523) so it might have introduced certain bugs in applications that depend on them.

Keep track of the issue on cx_freeze and remember that certain errors might pop up when using a newly released version of Python.


As an aside, since you import cx_Freeze and access setup and Executable through there, there's no need for the:

from cx_Freeze import setup, Executable

line. You aren't using those names.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...