Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I was able to solve this, and this should help others as well:</p> <ul> <li><p>Create the .spec file with the following command:</p> <pre><code>python Makespec.py --noconsole --icon="youricon.ico" --name="App name" program.py </code></pre></li> <li><p>Open the .spec file (eg.: App name/App name.spec) and you should see something like this:</p> <pre><code>a = Analysis([ os.path.join(HOMEPATH,'support\\_mountzlib.py'), os.path.join(HOMEPATH,'support\\useUnicode.py'), 'program.py' ], pathex=[ 'C:\\Your\\User\\Path\\To\\pyinstaller' ]) pyz = PYZ(a.pure) exe = EXE( pyz, a.scripts, exclude_binaries=1, name=os.path.join('build\\pyi.win32\\App Name', 'App Name.exe'), debug=False, strip=False, upx=True, console=False , icon='youricon.ico' ) coll = COLLECT( exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, name=os.path.join('dist', 'Hey Mang!') ) app = BUNDLE(coll, name=os.path.join('dist', 'Hey Mang!.app')) </code></pre> <p>And before <strong>a.binaries</strong> you should add this piece of code:</p> <pre><code> Tree('C:\\Your\\App\\Path\\To\\Images'), </code></pre> <p>So when PyInstaller reads the <strong>.spec file</strong>, the compiler will pass the image to the <strong>dist</strong> directory.</p></li> <li><p>Now we need to create the <strong>.qrc file</strong>, which will load our images. And this file should look something like this:</p> <pre><code>&lt;RCC&gt; &lt;qresource prefix="/" &gt; &lt;file&gt;img/image1.png&lt;/file&gt; &lt;file&gt;img/image2.png&lt;/file&gt; &lt;file&gt;img/image3.png&lt;/file&gt; &lt;/qresource&gt; &lt;/RCC&gt; </code></pre> <p>With your images, obviously. And this needs to be compiled to .py format, with the following command:</p> <pre><code>pyrcc4 -o images.qrc images_qr.py </code></pre></li> <li><p>And finally, we need to add this to our script, for example like this:</p> <pre><code>import images_qr ... self.setWindowIcon(QtGui.QIcon(':/img/image1.png')) # The colon must be there </code></pre></li> </ul> <p>And once you compile you should see the images just fine, like this:</p> <p><img src="https://i.stack.imgur.com/5r7qV.png" alt=""></p> <p>I hope this helps everyone with the same issue. Remember to give the proper image paths and to add the colon to your images.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload