Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PyInstaller can't change the shortcut icon

My problem is the following, while i can set any icon i like on the executable itself, i cannot change this one

enter image description here

I have tried everything but when i select the exe file or when i create a shortcut this PyInstaller icon will come up!

Here is how the exe looks itself

enter image description here

Here is the tricky part, this DOES NOT happen if i set the option --onefile. If i generate the stand-alone exe, this "additional" unwanted icon goes away!

and here is the spec file in case you need it:

# -*- mode: python -*-
a = Analysis(['Backpack.py'],
             pathex=['C:\\Users\\Angelo\\Desktop\\PyInstaller-2.1\\Backpack'],
             hiddenimports=[],
             hookspath=None,
             runtime_hooks=None)

a.datas += [('back_ico_3.ico', 'C:\\Users\\Angelo\\Desktop\\PyInstaller-2.1\\back_ico_3.ico', 'DATA')]

pyz = PYZ(a.pure)
exe = EXE(pyz,
          a.scripts,
          exclude_binaries=True,
          name='Backpack.exe',
          debug=False,
          strip=None,
          upx=True,
          console=False , icon='back_ico_3.ico')
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=None,
               upx=True,
               name='Backpack')
like image 801
Angelo Uknown Avatar asked Jun 23 '14 10:06

Angelo Uknown


People also ask

How do I change the icon in PyInstaller?

Use the --icon argument to specify a custom icon for the application. It will be copied into the Resources folder. (If you do not specify an icon file, PyInstaller supplies a file icon-windowed. icns with the PyInstaller logo.)

How do I change the icon of an exe file?

Click the “Action” menu and then select “Replace Icon.” In the Replace Icon window, click the “Open file with new icon” button and browse to the location of the icon you want to use. The source can be an EXE, DLL, RES, or ICO file. After you've selected the icon, it's displayed in the Replace Icon window.

Why is PyInstaller not working?

The most common reason a PyInstaller package fails is that PyInstaller failed to bundle a required file. Such missing files fall into a few categories: Hidden or missing imports: Sometimes PyInstaller can't detect the import of a package or library, typically because it is imported dynamically.

What is .spec file in Python?

The spec file tells PyInstaller how to process your script. It encodes the script names and most of the options you give to the pyinstaller command. The spec file is actually executable Python code. PyInstaller builds the app by executing the contents of the spec file.


2 Answers

I had this same problem, even when using --onefile. Cutting and pasting the .exe into a fresh directory worked.

Try deleting IconCache.db and rebooting if it still doesn't display your custom icon. It's in %localappdata%.

like image 90
Fred Avatar answered Oct 15 '22 18:10

Fred


Enable Hidden Items

Go to C:\Users\User\AppData\Local\Microsoft\Windows\Explorer. Select all files that begin with iconcache and thumbcache and delete all these files

Go to C:\Users\user\AppData\Local and delete IconCache.db

like image 20
ajinzrathod Avatar answered Oct 15 '22 16:10

ajinzrathod