I have set the icon for my PyQt application using self.setWindowIcon(QtGui.QIcon('icon.png')) and it works fine when I run my code in PyCharm.
Next I converted my application to one file with PyInstaller:
pyinstaller.exe --onefile --windowed opc.py --name myapps
However, when running the executable the icon is not shown. What am I doing wrong ?
On left site code from PyCharm, on right site from one file (pyinstaller.exe --onefile --windowed opc.py --name myapps).
Why is not the same ?
I want *.png icon because is transparent.
The icon displayed when running an executable on Windows comes from the executable file itself. To bundle an icon with your application you need to specify the icon when building with pyinstaller.exe by passing the --icon parameter. For example:
pyinstaller.exe --onefile --windowed --name myapps --icon=icon.ico opc.py
Note that unlike for setWindowIcon() the icon file must be in .ico format, so you will need to convert it from the .png first.
If you want to use the PyQt call to set the icon you will need to bundle the icon file into the executable, which can be done using a PyInstaller spec file. A walkthrough of the process of creating and modifying the spec file is in this previous answer.
Related
I created a pyinstaller .exe that is built correctly without any mistakes with pyinstaller. When I run it from the cmd, it runs perfectly, but when I double click the .exe file, it does not work. I read that has to do something with PyQt5, but I didn't make it work. This is the creation statement:
pyinstaller --paths
C:\Users\430350\AppData\Local\Programs\Python\Python36\Lib\site-
packages\PyQt5\Qt\bin "path" --hidden-import numpy.core._dtype_ctypes --hidden-
import fix_qt_import_error --icon=icon.ico --noconfirm
Thanks in advance!
Don’t know if it’s the same in Windows. But using pyinstaller in Linux with the -F option (pyinstaller -F file.py) with a PyQt5 project I have to add to the binary file folder .qss and .ui files manually my resource.py file and enclosed png. are not read too. Also did you check the versione you are using ? Python 2 vs 2, 3 vs 3 etc ... v
I've made a python program using Tkinter(GUI) and I would like to enter it by creating a dedicated icon on my desktop. (I want to send the file to my friend, without him having to install python or any interpreter)
the file is a some-what game that I want to share with friends and family, which are not familiar with coding.
You can simply use Pyinstaller to create a standalone .exe.
Run this from the Windows cmd to create a standalone executable file: pyinstaller.exe --onefile --noconsole --icon=your_image_here.ico app.py
you can install Pyinstaller by using pip
pip install pyinstaller
go to the directory where your file is saved and type:
pyinstaller.exe --onefile --windowed path/to/your/file.py
--onefile (compresses your files into one .exe file)
--windowed (removes the console when you run your file)
path/to/your/file.py (or simply file.py when you want to convert the file in the same directory)
if you have any error using it, remove the --windowed flag and run file.exe on command line to see the error
I used below command to get a custom icon for my .exe file but my custom icon doesnt appear on my exe file even after successful completion of the command :
pyinstaller --noconsole --onefile
--icon="C:\Users\anubhav.jhalani\Desktop\index.ico" run.py
What am I doing wrong here?
I am using pyinstaller to compile my programs. I cannot include files with the -i option. It doesn't compile and instead gives an error. The whole compiler crashes. My error code is here: https://pastebin.com/raw/UBTTMmke I was using powershell after I shift+right-clicked the directory in explorer.
Make sure you 'cd' first on your script's folder destination.
Make sure your image file is converted as .ico file and also in your script's folder
Then try compiling your script as:
pyinstaller --onefile --icon Your_logo.ico My_script.py
Also if you want your console not to pop up when the script is running you can use the 'windowed' option:
pyinstaller --onefile --windowed --icon Your_logo.ico My_script.py
I want the command line to not open because a tkinter interface will open.
I am using pyinstaller so it works when python isn't installed. I am using python 3.6.0.
Can I also have it so it is one exe file that doesn't need the other things to run.
To avoid the command line window, add --windowed to your PyInstaller command line.
To create an one-file bundle, add --onefile to your PyInstaller command line.
These are documented in PyInstaller's options. https://pyinstaller.readthedocs.io/en/stable/usage.html#options