python - 尝试使用 cx_Freeze 将 .py 文件转换为 .exe 时出现 TypeError : list indices must be integers or slices, not str

标签 python pygame cx-freeze

所以基本上我正在尝试使用 cx_Freeze 将 python 文件转换为可执行文件。我不断收到错误

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

当尝试构建它时,我不知道是什么原因造成的。有人可以给我一些帮助吗?错误出现在第 8 行,即带有 "include_file" 的部分。但是我不确定这条线有什么问题。非常感谢任何帮助,谢谢。

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

    )

最佳答案

我想象这条线

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"]}}

应该是

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"]}}

两个相邻的列表不会连接(就像字符串一样),列表后面的方括号是列表索引,因此 ["foo"]["bar"] 尝试使用"bar" 作为从列表 ["foo"] 中获取项目的索引。

关于python - 尝试使用 cx_Freeze 将 .py 文件转换为 .exe 时出现 TypeError : list indices must be integers or slices, not str,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57930474/

相关文章:

javascript - ajax html响应中的AngularJs数据绑定(bind)

python - 在种子中生成随机数

python - 如何创建我的 DataFrame 以仅在我的数据集的 'Language' 列中显示法国电影,而该列中有多种语言?

python - 如何修复对象图像无法正确加载的问题

python - 无法在 python 可执行文件上加载 mkl_intel_thread.dll

python - 使用 cx_Freeze 编译 Python C 扩展

python - 将文件解析为 JSON 文件的父/子格式

Python 从 git 进行 self 更新

python - 按空格键时图像显示 300 毫秒

python - cx_freeze 将项目构建为 .exe 文件,出现 numpy 导入错误