Add image to .spec file in Pyinstaller

后端 未结 3 1276
[愿得一人]
[愿得一人] 2020-12-30 14:56

Does anybody know how to modify the .spec file created with the Makespec.py of Pyinstaller such that it includes an image data in the _MEIPAS

3条回答
  •  执念已碎
    2020-12-30 15:42

    Here is my spec file (Collector.spec) I used for a simple python program called "Collector.py".

    # -*- mode: python -*-
    a = Analysis(['Collector.py'],
                 pathex=['C:\\Users\\vijay\\Python\\Collector'],
                 hiddenimports=[],
                 hookspath=None,
                 runtime_hooks=None)
    a.datas += [('logo.png','C:\\Users\\vijay\\System\\icon\\logo.png','DATA')]
    pyz = PYZ(a.pure)
    exe = EXE(pyz,
              a.scripts,
              a.binaries,
              a.zipfiles,
              a.datas,
              name='Collector.exe',
              debug=False,
              strip=None,
              upx=True,
              console=False , icon='C:\\Users\\vijay\\System\\icon\\logo.ico')
    

    The line "a.datas += .... " just above pyz variable holds the path to png image that will be displayed on various windows of my GUI application. The "icon=...." variable set inside exe variable, holds the path to ico image that will be displayed on Windows Desktop as the Desktop Icon.

    You can now use what Max has done here in your main program (Collector.py, for me).

    Here is a snippet of my script Collector.py, where I've made use of Max's Code:

    path = self.resource_path("logo.png")
    icon = wx.Icon(path, wx.BITMAP_TYPE_PNG)
    self.SetIcon(icon)
    

    Now, when I run pyinstaller Collector.spec, I have both a Desktop Icon and an Icon for my Collector App windows.

    Hope this helps!

提交回复
热议问题