AQuick
AQuick

Reputation: 176

Setting Icon for PyInstaller Application

I have been all over Google, Reddit, StackOverflow, PyInstaller docs, I can't figure this out.

I'm trying to set my icon for my application, but it will not work. The icon is applied to the main exe, however, the icon does not show in the taskbar when it is open for Windows.

The icon is being included. I have set the value icon in EXE directly to the icon path. I have used Resource Hacker, I have used RCEDIT, which by the way, kills my application entirely. I, for the life of me, CANNOT get the icon of the application to show correctly.

I have tried Windows 10 and Windows 7.

Even when I run Pyinstaller without -F, it still won't load the icon. I'm 100% certain my file is an .ico file, and includes multiple acceptable sizes, Resource Hacker showed all acceptable sizes for the .ico.



Here is the powershell command I'm using:

pyinstaller -F -i C:\aNote\theme\anoteicon.ico --clean anotemain.spec

Here is my .spec

# -*- mode: python -*-

block_cipher = None


a = Analysis(['anotemain.py'],
             pathex=['C:\\aNote'],
             binaries=[],
             datas=[('c:\\aNote\\theme\\anoteicon.png','theme'), 
             ('c:\\aNote\\theme\\kabook.png','theme'), 
             ('c:\\aNote\\theme\\Python.svg.png','theme'), 
             ('c:\\aNote\\theme\\anoteicon.ico','.'), 
             ('c:\\aNote\\anoteui.py','.'),
             ('c:\\aNote\\version.txt','.')],
             hiddenimports=["PyQt5.sip", "QtGui", "QtWidgets", "pyperclip", "webbrowser", "csv"],
             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='aNote',
          debug=False,
          strip=False,
          upx=False,
          clean=True,
          runtime_tmpdir=None,
          console=False,
          icon='c:\\aNote\\theme\\anoteicon.ico',
          version='version.txt')

Upvotes: 8

Views: 56555

Answers (4)

Vladimir
Vladimir

Reputation: 6756

Simple and fast solution:

Suppose you are using:

Pyinstaller.exe --onefile --windowed --icon=app.ico app.py

But Pyinstaller not manage taskbar icon.

Replace icon file for taskbar in your venv, example:

C:\python\venv\myproj311-32\Lib\site-packages\pygame\pygame_icon.bmp

No extra dependencies, no edit .spec

Upvotes: 0

W Kenny
W Kenny

Reputation: 2089

I solve it by using the command -i instead of --icon

python -m PyInstaller --onefile -i='.\angular.ico' --name "MyApp" ".\main.py"

Upvotes: 1

Go in CMD to folder with your script ( cd /Project ) If your folder in d:, firsly d: then cd /Project

Enter pyinstaller -w -F -i "icon.ico" script.py

Or if you app is console then pyinstaller -F -i "icon.ico" script.py

Upvotes: 5

Saige Zhang
Saige Zhang

Reputation: 797

Have you tried this command?

Pyinstaller.exe --onefile --windowed --icon=app.ico app.py

Update your .specfile and set console = True

exe = EXE(pyz,
      a.scripts,
      a.binaries,
      a.zipfiles,
      a.datas,
      name='aNote',
      debug=False,
      strip=False,
      upx=False,
      clean=True,
      runtime_tmpdir=None,
      console=True,
      icon='c:\\aNote\\theme\\anoteicon.ico',
      version='version.txt')

Use the sample code you can run a window UI instead of console:

from PyQt5 import QtGui

app = QtGui.QApplication([])
mainwindow = QtGui.QMainWindow()
mainwindow.show()

app.setWindowIcon(QtGui.QIcon('your.ico'))
mainwindow.setWindowIcon(QtGui.QIcon('your.ico'))
app.exec_()

Upvotes: 5

Related Questions