Python Pyinstaller 设置图标
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29291113/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Pyinstaller setting icon
提问by Somputer
I use command that:
我使用命令:
pyinstaller.exe --icon=test.ico -F --noconsole test.py
All icons do not change to test.ico
所有图标都不会更改为 test.ico
Some icons remain default(pyinstaller) icon...
一些图标保持默认(pyinstaller)图标...
Why?
为什么?
all icon change OS -> windows 7 32bit, windows 7 64bit(make exe file OS)
所有图标更改 OS -> windows 7 32bit, windows 7 64bit(make exe file OS)
remain default icon OS -> windows 7 64bit(other PC)
保留默认图标 OS -> windows 7 64bit(其他 PC)
采纳答案by J. Saw
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
:
我知道这是旧的和诸如此类的(并不确定这是否是一个问题),但是在搜索之后,我成功使用了以下命令--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.
当我搜索有关如何为我的 .exe 设置图标的答案时,Google 将我引导到此页面,因此也许它会对其他人有所帮助。
The information here was found at this site: https://mborgerson.com/creating-an-executable-from-a-python-script
这里的信息是在这个站点上找到的:https: //mborgerson.com/creating-an-executable-from-a-python-script
回答by Alan L
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.
我认为这可能与缓存有关(可能在 Windows 资源管理器中)。我在一些地方也显示了旧的 PyInstaller 图标,但是当我将 exe 复制到其他地方时,所有旧图标都消失了。
回答by Avinash Poshiya
Below command can set the ICON on executable file. Remember the ".ico" file should present in the place of path given in "Path_of_.ico_file".
下面的命令可以在可执行文件上设置图标。请记住,“.ico”文件应出现在“Path_of_.ico_file”中给出的路径位置。
pyinstaller.exe --onefile --windowed --icon="Path_of_.ico_file" app.py
pyinstaller.exe --onefile --windowed --icon="Path_of_.ico_file" app.py
For ex: app.py file present in current directory and 'app.ico'is present inside the 'Images' folderwhich is created in current directory. So the command should given below. The final executable file will be generate inside the 'dist' folder.
例如:当前目录中存在 app.py 文件,当前目录中创建的“Images”文件夹中存在“app.ico”。所以命令应该在下面给出。最终的可执行文件将在“dist”文件夹中生成。
pyinstaller.exe --onefile --windowed --icon=Images\app.ico app.py
pyinstaller.exe --onefile --windowed --icon=Images\app.ico app.py
回答by Abhisek Upadhaya
Here is how you can add icon while creating exe file from python file-
这是在从 python 文件创建 exe 文件时添加图标的方法 -
open command promp from where python file exist and type -
从 python 文件所在的位置打开命令提示符并键入 -
pyinstaller --onefile -i"path of icon" path of python file
pyinstaller --onefile -i"path of icon" python文件的路径
Example-
例子-
pyinstaller --onefile -i"C:\icon\Robot.ico" C:\Users\Jarvis.py
pyinstaller --onefile -i"C:\icon\Robot.ico" C:\Users\Jarvis.py
This is the easiest way to add icon. It really works. I am 100% sure.
这是添加图标的最简单方法。真的行。我百分百肯定。