About packaging

The pyqt5 program, many people have been using pyinstaller to package it, and I have been using it all the time. It can be marked as [single exe executable file] or [installation-free green folder].

There are many articles and tutorials related to pyinstaller on the Internet. You can search by yourself. I have written a few articles myself. You can refer to: “[Climbing pit] various problems with python3+pyqt5+pyinstaller” “Use template packaged by pyinstaller using spec file”

About the update

Software update, most of which are Update.exe + main program.exe, why? Because it is impossible for a program to update itself when it is running, Update.exe is used to update the main program.exe. Like the login interface of many terminal games, it is actually a version updater, which is Update.exe.

But our pyqt5 is often marked as a single exe executable file, and we don’t want to add another Update.exe program, what should we do?

The question is transformed, that is: how to realize self-update of a single exe executable file of pyqt5?

Actually, the solution, think about it a little, everyone has it, I use this:

Step 1: Use the old main program.exe, download the new main program.exe, and put it in a custom update directory. Step 2: Close the old main program.exe Step 3: Delete the old main program.exe Step 4: Copy the new main program.exe to the directory location of the old main program.exe

With such a solution, how to achieve it?How to do it beautifully?

This article draws on this great god “Winform single exe to achieve self-update skills”

The vbs script is used here, and some automated processing is done through the vbs script. Then, the solution, embodied, is this:

Step 0. Edit and save the vbs file in advance Step 1. Click the update button, then download the new main program .exe and vbs file, and put them together in the update directory. Step 2. After downloading, run the vbs file Step 3. The vbs file is running…close the old main program.exe Step 4. The vbs file is running…delete the old main program.exe Step 5. The vbs file is running…copy the new main program.exe to the directory location of the old main program.exe Step 6. The vbs file is running…open the new main program.exe Step7. The vbs file is running… it’s over, what else do you want to do, add it as needed

Core code

The main program.exe and vbs file, after downloading, have to run the vbs file, python runs the vbs file like this

import subprocessCREATE_NO_WINDOW = 0x08000000 #If you don't add this, there will be a cscript window, which doesn't look goodsubprocess.call("cscript update.vbs", creationflags=CREATE_NO_WINDOW)

update.vbs script code, as follows

Dim wshSet wsh = WScript.CreateObject("WScript.Shell")Dim fsoSet fso = CreateObject("Scripting.FileSystemObject")DesktopPath = wsh.SpecialFolders("Desktop")UpdatePath = "C:\mysoft_update"'Clear the old program processwsh.Run "taskkill /f /im mysoft.exe",0WScript.Sleep(2000)'Remove old programsIf fso.fileExists(DesktopPath & "\mysoft.exe") Thenfso.DeleteFile(DesktopPath & "\mysoft.exe")WScript.Sleep(2000)End If'Copy the new program to the desktopIf fso.fileExists(UpdatePath & "\mysoft.exe") Thenfso.CopyFile UpdatePath & "\mysoft.exe", DesktopPath & "\mysoft.exe"WScript.Sleep(2000)End If'Run the new programIf fso.fileExists(DesktopPath & "\mysoft.exe") Thenwsh.Run DesktopPath &"\mysoft.exe",false,falseEnd If'Final processingSet fso=NoThingWScript.quitSet wsh=NoThingWScript.quit

at the end

Okay, this is basically the case. It took me a long time to learn these few vbs. Let’s use it.

The whole thing, of course, there are other codes, but it is too long to be posted here. Please read more of your own articles and spell it out

If you don’t know how to write the download function, read my article here, copy it, and spell it out

“Pyqt5 Download Progress Bar – Implementation Template”

The articles I write are generally information that can’t be found by Baidu. I think everyone needs them, so I write them down. I hope they will be helpful to everyone

Welcome everyone, like, follow, leave a message to show your support…Thank you!