如何将 python 文件转换成包含多个其他文件的 exe?

How to convert python file into exe which has multiple other files with it?

我正在尝试使用 Pyinstaller 制作我的程序的 exe 文件,但我的程序涉及 py 脚本目录内另一个文件夹中的图像。 我也不确定如何将照片文件夹添加到 exe 文件,因为如果我将主 python 文件制作成 exe,我会收到一条错误消息,说它不能 find/access 图片。

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

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

--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,但它可以是任何东西。