Icon from pyqt5/pyside2 resources

Tiago_Piontkewicz | 2020-09-11 20:15:36 UTC | #1

Hello,

trying to package an application following the " Packaging PyQt5 & PySide2 applications for Windows, with PyInstaller" post, I set the icon argument in Pyinstaller like this:

python
--icon=myicon.ico

The myicon.ico file is inside my resource (qrc), converted to Python code. The command was unsucessful, generating the error "Unable to open icon file myicon.ico".

According to the post " The advantage of this method is that your data files are guaranteed to be bundled as they are treated as code — PyInstaller finds them through the imports in your source."

Is the post wrong orI'm doing something wrong?


martin | 2020-09-11 20:15:47 UTC | #2

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt6
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

Hi @Tiago_Piontkewicz welcome to the forum, and sorry for the slow answer.

It's just a misunderstanding I think --

When you issue the PyInstaller command like this, you're not inside your Python package, so the contents of the QRC file aren't accessible. The QRC is only used from within the Python/PyQt5 code -- PyInstaller doesn't know anything about it.

So you need to pass PyInstaller the full path to the icon file -- it should still exist as a separate file, even if it's being bundled in the QRC file for use in your code.

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PyQt6 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!

More info Get the book


Tiago_Piontkewicz | 2020-07-13 20:38:40 UTC | #3

Understood.

Thanks for clarify this question.


PyQt6 Crash Course by Martin Fitzpatrick — The important parts of PyQt6 in bite-size chunks

See the course

Mark As Complete
Martin Fitzpatrick

Icon from pyqt5/pyside2 resources was written by Martin Fitzpatrick .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt.