Search code examples
pythonpygamecx-freeze

TypeError: list indices must be integers or slices, not str when trying to convert .py file to .exe with cx_Freeze


So basically I'm trying to convert a python file to an executable using cx_Freeze. I keep getting an error

TypeError: list indices must be integers or slices, not str

when trying to build it and I have no idea what is causing it. Can anyone give me some help? The error is on line 8, the part with the "include_file". However I'm unsure as to what is wrong with this line. Would really appreciate any help thank you.

import cx_Freeze
executables = [cx_Freeze.Executable("Consumo V23.py")]

cx_Freeze.setup(
    name="A bit Racey",
    options={"build_exe": {"packages":["pygame"],
                           "include_files":["Blowfish.png"]["dojo.png"]["Rice_fresh.png"]["rottenapple.png"]["rottenfish.png"]["rottenrice.png"]
                           ["menu screen .png"]["gameover.png"]["Apple .png"]["Fish.png"]}},
    executables = executables

    )

Solution

  • I imagine this line

    options={"build_exe": {"packages":["pygame"],
                           "include_files":["Blowfish.png"]["dojo.png"]["Rice_fresh.png"]["rottenapple.png"]["rottenfish.png"]["rottenrice.png"]
                           ["menu screen .png"]["gameover.png"]["Apple .png"]["Fish.png"]}}
    

    Should be

    options={"build_exe": {"packages":["pygame"],
                           "include_files":["Blowfish.png", "dojo.png", "Rice_fresh.png", "rottenapple.png", "rottenfish.png", "rottenrice.png", "menu screen.png", "gameover.png", "Apple .png", "Fish.png"]}}
    

    Two lists next to each other don't concatenate (like strings do), the square brackets after a list are list indices so ["foo"]["bar"] is trying to use "bar" as an index to get an item from the list ["foo"].