Pyinstaller 设置图标不改变

问题描述 投票:0回答:12

当我使用命令时:

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

所有图标均不会更改为 test.ico。一些图标保留为 pyinstaller 的默认图标。

为什么?

所有图标更改

  • Windows 7 32 位
  • windows 7 64bit(制作exe文件操作系统)

有些保持默认

  • windows 7 64位(其他电脑)
python icons pyinstaller executable
12个回答
123
投票

我知道这已经很旧了(并且不确定这是否是一个问题),但是经过搜索,我成功使用了这个命令

--onefile

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

当我正在寻找有关如何为我的 .exe 设置图标的答案时,Google 将我带到了此页面,所以也许它会对其他人有所帮助。

此处的信息可在以下网站找到:https://mborgerson.com/creating-an-executable-from-a-python-script


60
投票

我认为这可能与缓存有关(可能在 Windows 资源管理器中)。我的旧 PyInstaller 图标也出现在一些地方,但是当我将 exe 复制到其他地方时,所有旧图标都消失了。


17
投票

以下命令可以在可执行文件上设置图标。

记住“.ico”文件应出现在“Path_of_.ico_file”中给出的路径位置。

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

例如:

如果

app.py
文件存在于当前目录中并且
app.ico
存在于当前目录中的
Images folder
内。

那么命令应该如下所示。最终的可执行文件将在

dist folder

内生成
pyinstaller.exe --onefile --windowed --icon=Images\app.ico app.py

10
投票

我也有类似的问题。如果 pyinstaller 没有错误,请尝试更改 .exe 文件的名称。对我有用


5
投票

我的解决方案是刷新Windows资源管理器的图标缓存

对于 Windows 10:在 Windows 运行中输入“ie4uinit.exe -show”

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


4
投票

以下是如何在从 Python 文件创建 exe 文件时添加图标

  • 在Python文件存在的地方打开命令提示符

  • 类型:

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

示例-

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

这是添加图标最简单的方法。


2
投票

如果您想设置默认图标,而不是 pyinstaller 为您设置的图标,则在构建 EXE 时有一个选项,只需在命令中添加“-i NONE”即可。默认操作系统图标将应用于您的可执行文件。

pyinstaller --onefile --clean -i NONE --noconsole

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


1
投票

就我而言,文件的新图标没有显示在 dist 文件夹中,而是仅当我将图标移动到桌面上时才出现。


1
投票

很老了。我遇到了同样的问题,但还有其他问题,例如即使条目文件的一些更改停止在INFO:检查 EXE,它也没有真正构建应用程序。

我通过删除由

app.spec
生成的
build
pyinstaller
文件夹解决了这个问题和我的问题。

图标确实更新了(请参阅左上角的应用程序图标),我认为窗口只是缓存了它。


0
投票

这是 pyinstaller 中的一个模块的错误。 东西会是这样的,对吧:

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'

0
投票
pyinstaller --clean --onefile --icon=default.ico Registry.py

它对我有用


0
投票

有时,窗口没有清除缓存。

需要在cmd上运行这个脚本

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

© www.soinside.com 2019 - 2024. All rights reserved.