Pyinstaller - .ico 文件仍未包含在 .spec 中(--onefile)

Pyinstaller - .ico file still not included from .spec (--onefile)

我正在尝试使用 pyinstaller 为我的 Python 程序制作 .exe。我更改了 .spec 文件的数据,以便它包含我程序的 .ico 文件,但它仍然说它在执行时缺少 .ico。

spec文件(Raven.py是我的程序,raven.ico是它需要的.ico文件):

# -*- mode: python -*-

block_cipher = None


a = Analysis(['C:\Users\Andrew\Desktop\project\Raven.py'],
         pathex=['C:\Users\Andrew'],
         binaries=None,
         datas=[ ('C:\Users\Andrew\Desktop\project\raven.ico', '.') ],
         hiddenimports=[],
         hookspath=[],
         runtime_hooks=[],
         excludes=[],
         win_no_prefer_redirects=False,
         win_private_assemblies=False,
         cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
         cipher=block_cipher)
exe = EXE(pyz,
         a.scripts,
         a.binaries,
         a.zipfiles,
         a.datas,
         name='Raven',
         debug=False,
         strip=False,
         upx=True,
         console=True )

这是我在 pyinstaller 命令提示符中输入的内容:

pyinstaller --onefile C:\Users\Andrew\Raven.spec

然后它像它的工作一样运行并创建 .exe 文件,该文件说它丢失 raven.ico 并终止。

将 .ico 文件添加到与 .exe 相同的目录中可以使程序完美运行。

此外,如果重要的话,我正在使用 Tkinter 并且 Raven.py 导入了我的另外两个 python 文件。

您应该在规范中添加选项图标。如果你想添加

'C:\Users\Andrew\Desktop\project\raven.ico'

你应该使用

# -*- mode: python -*-

block_cipher = None


a = Analysis(['C:\Users\Andrew\Desktop\project\Raven.py'],
     pathex=['C:\Users\Andrew'],
     binaries=None,
     datas=[ ('C:\Users\Andrew\Desktop\project\raven.ico', '.') ],
     hiddenimports=[],
     hookspath=[],
     runtime_hooks=[],
     excludes=[],
     win_no_prefer_redirects=False,
     win_private_assemblies=False,
     cipher=block_cipher)
pyz = PYZ(a.pure, a.zipped_data,
     cipher=block_cipher)
exe = EXE(pyz,
     a.scripts,
     a.binaries,
     a.zipfiles,
     a.datas,
     name='Raven',
     debug=False,
     strip=False,
     upx=True,
     console=True , icon='C:\Users\Andrew\Desktop\project\raven.ico')