指定要包含在 pyinstaller exe 中的文件夹

Specifying folders to be included in pyinstaller exe

所以我正在用 PySimpleGui 编写测试 python 程序,它看起来像这样:

import PySimpleGUI as sg
import sys

# This bit gets the taskbar icon working properly in Windows
if sys.platform.startswith('win'):
    import ctypes
    if not sys.argv[0].endswith('.exe'):
        ctypes.windll.shell32.SetCurrentProcessExplicitAppUserModelID(u'Ethan.FileManager.filemanager.1')

sg.theme('DarkAmber')  # Add a touch of color
# All the stuff inside your window.
layout = [[sg.Text('File Manager')],
          [sg.Text('Input goes here'), sg.InputText()],
          [sg.Button('Ok')]]

# Create the Window
window = sg.Window('File Manager', layout, icon="assets/rickroll.ico")
# Event Loop to process "events" and get the "values" of the inputs
while True:
    event, values = window.read()
    if event == sg.WIN_CLOSED:  # if user closes window or clicks cancel
        break
    elif values[0] == "":
        break
    print('You entered', values[0])
    window.close()
    window = sg.Window('File Manager', [[sg.Text(f'you entered {values[0]}')]], icon="rickroll.ico")

window.close()

我想在完成后将其作为可执行文件分发,但我无法在 pyinstaller 构建中包含资产文件夹。如果有人可以给我关于如何包含该文件夹的提示,或者指出可以的地方,那就太好了。感兴趣的文件是 main.py,在资产文件夹中,有一个名为 rickroll.ico 的文件。谢谢!

所以我确实尝试对图像使用 base64 编码,但是它有很多,这让我的代码看起来有点古怪,所以我最终做的是使用 --add-data "files/icon.ico;files" 将图标与 exe 打包在一起,这最终与 this answer

一起工作