I’m building a python app which is to pack up as a single executable and work on Windows, MacOS and Linux. Have made a lot of progress and am using a workflow on Github to build using pyinstaller for each OS. Most things are working fine.
Right now I am working on getting an icon onto the executable instead of the default system icon.
I have a spec
file for pyinstaller and I have a section where the icon is mentioned:
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.zipfiles,
a.datas,
[],
name='my_app_name',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='images/my_icon.ico'
)
This seems to work well for Windows and the output exe file has my icon which is great.
My question is, is there a way to do this for Linux. I know that normally for Linux you need to build a .desktop
file, so I guess the question is three-fold:
- Is there a way to give a file an icon without a desktop file (in Linux)?
or
- Is there a way to somehow build and connect a desktop file to my Linux file in pyinstaller?
or
- Is there some python way to self-create a desktop file for my python app?
Thanks
2
Answers
OK, so I found a a way to do it - not really in pyinstaller, but it works for me.
I am building my app(s) using Github's Workflow feature - so we have a file called
python_build.yml
under/.github/workflows
So, after building the executable with pyinstaller into a single file I have:
So, there's a couple of important points to add to this. I have saved in my Git repository a small directory structure named my-app. I don't think this is the web page I used but it's similar. Basically a folder named my-app with two folders underneath it :
DEBIAN
andusr
. In theDEBIAN
there is one file calledcontrol
with something like this in it:Under
usr
is a foldershare
which has three more folders under itapplications
,bin
andicons
. Thebin
folder has (in my Git repository) an empty file calledhold
just so that the directory structure is maintained in Git - you can see that thehold
file is deleted and replaced by the compiled binary after pyinstaller is finished. The Desktop file itself is underapplications
and looks like this:Hope this helps someone!
There’s such a pip library as a auto-py-to-exe. It’s UI for pyinstaller and it makes it quite easier to create exe. Try to apply icon though that stuff.
I think it also should work for Linux as for Windows. But for me there were some errors if l created few files with same name and different icons. Not sure if it was problem of pyinstaller.
Auto-py-to-exe UI