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

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

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

        layout = QVBoxLayout()

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


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

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.

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.

from PyQt5.QtWinExtras import QtWin
myappid = 'com.qinhong.something'

and the icon should work as expected.

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

The complete guide to packaging Python GUI applications with PyInstaller.
[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]
Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak

I developed a simple demo and packed it with pyinstaller 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.