Pyinstaller setting icons don't change
Asked Answered
B

15

77

When I use the command:

pyinstaller.exe --icon=test.ico -F --noconsole test.py

All icons do not change to test.ico. Some icons remain as the pyinstaller's default icon.

Why?

All icon change in

  • windows 7 32bit
  • windows 7 64bit (make an exe file OS)

Some remain default

  • windows 7 64bit (other PC)
Burnt answered 27/3, 2015 at 0:5 Comment(0)
K
133

I know this is old and whatnot (and not exactly sure if it's a question), but after searching, I had success with this command for --onefile:

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

Google led me to this page while I was searching for an answer on how to set an icon for my .exe, so maybe it will help someone else.

The information here was found at this site: https://mborgerson.com/creating-an-executable-from-a-python-script

Konstantine answered 6/11, 2015 at 1:50 Comment(5)
You can also add the icon to your .spec file as done here: shanetully.com/2013/08/…Drogheda
pyinstaller.exe --onefile --icon=app.ico helloworld.py < -- Not working for me. What am i doing wrong?Winshell
does this work on .sh python script in ubuntu?Ghoul
The icons are cached by windows explorer.Incoming
In windows (in file explorer) list view there is an error (it shows the default disket icon), but in large or medium icons it shows the file that's included with pyinstaller command.Chinachinaberry
C
66

I think this might have something to do with caching (possibly in Windows Explorer). I was having the old PyInstaller icon show up in a few places too, but when I copied the exe somewhere else, all the old icons were gone.

Chud answered 3/3, 2016 at 21:17 Comment(6)
Yeah, it seems Explorer does some caching when the .exe file is first shown, so a rebuild with an icon did not reflect the change until the .exe was shown in another directory.Sebaceous
I had the same issue. Thank you.Ainslie
Same issue here. Closing and reopening the window doesn't help, but copying the executable elsewhere will show the correct icon.Orr
In Windows, you can restart Windows Explorer: Task Manager -> Process -> Windows processes -> Windows Explorer. Click Restart. The cache will be cleared and the correct icon will be displayed.Daloris
Thank you for this, saved me a huge headache since I thought I was doing something wrong. Stupid WindowsMagnetron
Great! had the same issue, now it's solved.Appall
P
17

The below command can set the icon on an executable file.

Remember the ".ico" file should present in the place of the path given in "Path_of_.ico_file".

pyinstaller.exe --onefile --windowed --icon="Path_of_.ico_file" app.py

For example:

If the app.py file is present in the current directory and app.ico is present inside the Images folder within the current directory.

Then the command should be as below. The final executable file will be generated inside the dist folder

pyinstaller.exe --onefile --windowed --icon=Images\app.ico app.py
Plaintive answered 5/3, 2018 at 10:56 Comment(0)
D
10

I had similar problem. If no errors from pyinstaller try to change name of .exe file. It works for me

Daviddavida answered 21/2, 2021 at 11:7 Comment(2)
Works, but i tried to upload the file on google drive with the modified title, download it and then the default disket icon is appeared. I tried to modified it again but icon change in the second time.Chinachinaberry
@ChrisP this is because of windows icon cache. Checkout superuser.com/a/499079/357349Iddo
P
7

The solution for me was refresh the icon cache of the windows explorer

for Windows 10: Enter "ie4uinit.exe -show" in Windows run

Link: https://superuser.com/questions/499078/refresh-icon-cache-without-rebooting

Peripatetic answered 7/6, 2022 at 12:15 Comment(1)
This didn't work for me, however, I noticed when I right-clicked the file and selected "properties" the icon was correct, despite the icon not showing correctly in explorer. I just had to restart explorer.exeMukerji
W
4

Here is how you can add an icon while creating an exe file from a Python file

  • open command prompt at the place where Python file exist

  • type:

    pyinstaller --onefile -i"path of icon"  path of python file
    

Example-

pyinstaller --onefile -i"C:\icon\Robot.ico" C:\Users\Jarvis.py

This is the easiest way to add an icon.

Worsham answered 24/10, 2019 at 20:32 Comment(0)
D
2

if you want to set the default icon, not the one pyinstaller sets for you there is an option while building EXE just add "-i NONE" in command.The default os icon will be applied to your executable.

pyinstaller --onefile --clean -i NONE <filename.py> --noconsole

reference https://pyinstaller.readthedocs.io/en/stable/man/pyinstaller.html#windows-and-mac-os-x-specific-options

Dustan answered 14/4, 2021 at 5:13 Comment(0)
M
1

In my case, the new icon of the file did not show up in the dist folder but appeared only when I moved the icon on the Desktop.

Mandelbaum answered 24/10, 2021 at 17:12 Comment(2)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Commemorate
That is correct, Windows caches the icons for some files, so if you initially built the exe with no icon then added the icon, you will still see the initial/default icon from pyinstaller.Berlioz
G
1

Very old tho. I encountered same problem but with additional stuff like it's not really building the application even with some changes of the entry file stopping at INFO: Checking EXE.

I solved this and my problem by deleting the app.spec and build folder that was genereated by the pyinstaller.

The icon is really updated (see the app icon at upper left), window just cached it I think.

Greenhorn answered 26/12, 2022 at 3:42 Comment(0)
C
1

Sometimes, the window didnt clear the cache.

need to run this script on the cmd

taskkill /IM explorer.exe /F CD /d %userprofile%\AppData\Local DEL IconCache.db /a explorer.exe

Clow answered 20/10, 2023 at 7:11 Comment(2)
This is what worked for me! I just deleted the IconCache.db and rebooted...Tunis
In my case, all I had to do was restart explorer.Mukerji
W
0

That's error of a module in pyinstaller. The stuff would be sth like this, right:

File "c:\users\p-stu\appdata\local\programs\python\python38-32\lib\site-packages\PyInstaller\utils\win32\icon.py", line 234, in CopyIcons
    except win32api.error as W32E:
AttrubuteError: module 'win32ctypes.pywin32.win32api' has no attribute 'error'
Wintertime answered 21/6, 2020 at 6:14 Comment(0)
A
0
pyinstaller --clean --onefile --icon=default.ico Registry.py

It works for Me

Alpine answered 14/10, 2020 at 8:55 Comment(1)
Welcome to SO! When answering to an old question (this one is over 5 years old) that already has an accepted answer (that's the case here) make sure your answer adds something substantially new. Don’t answer if not.Jape
F
0

its just delete all files in build and dist and repeat the process using: pyinstaller --onefile --icon=default.ico Registry.py

Francefrancene answered 10/12, 2023 at 1:50 Comment(0)
F
0

When I copied the file over to another machine, icons stopped working (I had used --icon=myicon.ico).

So I Right-Click on the exe file/shortcut of the exe file -> Properties -> click “Change Icon” button -> Browse for the .ico file and hit OK,OK

Forehand answered 24/1 at 11:42 Comment(0)
H
0

This works for me. Note: main.py and icon.ico files are in same folder.

Command:

pyinstaller --onefile --icon "icon.ico" --name MyApp main.py
Hue answered 2/6 at 10:24 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.