I developed a simple demo and packed it with pyinstaller

Heads up! You've already completed this tutorial.

qinhong_lai | 2020-05-28 06:06:06 UTC | #1

Thank you. You have successfully solved this problem and obtained the file path and name. Now I have another problem

python
from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QVBoxLayout
from PyQt5.QtGui import *
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()

        layout = QVBoxLayout()

        for arg in sys.argv:  # <1> sys.argv is a list of strings.
            l = QLabel(arg)
            layout.addWidget(l)

        self.setWindowIcon(QIcon('resource/logo.ico'))
        self.setLayout(layout)
        self.setWindowTitle("Arguments")

app = QApplication(sys.argv)
w = Window()
w.show()
app.exec_()

I want to add a program icon self.setWindowIcon(QIcon('resource/logo.ico')) It can be displayed normally

But I use pyinstaller to package and generate exe pyinstaller -w test20.py

When the .MP4 video file on the desktop of the computer is opened through test20.exe, it will not be normal displayed. That's why I can only copy one picture to the desktop,This is not the way to do it 43|404x91


martin | 2020-05-28 08:24:13 UTC | #2

Ah, that's interesting -- you when you run it as a packaged app, the exe file is the first argument? That's kind of helpful. In that case you can just use sys.argv[1] or get the last argument in the list, e.g.

python
mp4_filename = sys.argv[-1]

That’s why I can only copy one picture to the desktop,This is not the way to do it

I'm not sure what you mean here?

Are you having problems setting the icon for the executable? In the PyInstaller tutorial https://www.pythonguis.com/courses/packaging-and-distribution/packaging-pyqt5-pyside2-applications-windows-pyinstaller/ it explains the problem -- add the following to the top of your file.

python
from PyQt5.QtWinExtras import QtWin
myappid = 'com.qinhong.something'
QtWin.setCurrentProcessExplicitAppUserModelID(myappid)    

and the icon should work as expected.

That tutorial also explains how to bundle the icons with your app.


Over 10,000 developers have bought Create GUI Applications with Python & Qt!

To support developers in [[ countryRegion ]] I give a [[ localizedDiscount[couponCode] ]]% discount with the code [[ couponCode ]] — Enjoy!

For [[ activeDiscount.description ]] I'm giving a [[ activeDiscount.discount ]]% discount with the code [[ couponCode ]] — Enjoy!

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak