【问题标题】:How to convert python file into exe which has multiple other files with it?如何将python文件转换为具有多个其他文件的exe?
【发布时间】:2020-11-15 23:03:22
【问题描述】:

我正在尝试使用 Pyinstaller 制作我的程序的 exe 文件,但我的程序涉及 py 脚本目录中另一个文件夹中的图像。 我也不确定如何将照片文件夹添加到 exe 文件中,因为如果我确实将主要的 python 文件变成了 exe,我会收到一个错误,说它无法找到/访问图像。

这是我的文件夹的样子,icons 文件夹是所有图像所在的位置,而 player.py 文件是主文件:

是否有我应该为 pyinstaller 使用的特定命令?

【问题讨论】:

    标签: python pyinstaller


    【解决方案1】:

    --add-data--add-binary 标志在这里会派上用场。来自documentation

    --add-data <SRC;DEST or SRC:DEST>
        Additional non-binary files or folders to be added to the executable. The
        path separator is platform specific, `os.pathsep` (which is ; on Windows
        and : on most unix systems) is used. This option can be used multiple
        times.
    

    所以在我们的例子中,我们或许可以这样做:

    > pyinstaller player.py --add-data Icons:<destination-directory-name>
    

    其中destination-directory-name 是您在脚本中实际使用的目录名称。我想它也会是Icons,但它可以是任何东西。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-09-29
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      • 2019-07-13
      • 2016-11-21
      相关资源
      最近更新 更多