0

I have an application built with PyQT5 for both Windows and macOS. Currently, the user checks for updates by clicking the button and when there is a new update available I am redirecting them to the browser to my server to download the latest .exe (Windows) or .pkg (macOS). The issue is for say if the user downloads and installs the latest version in a different location than the previous one which will result in two instances of the same application.

I want to improve the user experience and make an auto-updater like all the established applications. When the user clicks the updates the application should download the new updates without making any hassles for the users and update the application for both the OS.

For Windows, I am using Pyinstaller to make the .exe file and then Inno Setup to make it executable. Moreover, for macOS I am using setuptools to make the .app and macOS packages app to make it executable.

It would be really great if someone could help me to implement an update feature for my PyQT5 application.

Mehadi
  • 85
  • 8

1 Answers1

0

Hi there I have made a program where it can update itself, I was using tkinter, but it should work for PyQT5 if the same widgets are there. We are using GitHub for the program to download from there. Also I am on windows so I don't know if this works on mac. Here is my code:

import tkinter as tk #for you it is pyqt5
from tkinter import * #MessageBox and Button
import requests #pip install requests
import os #part of standard library
import sys #part of standard library

VERSION = 4

b1 = Button(frame, text = "Back", command = homepage)
b1.pack(ipadx= 10, ipady = 10, fill = X, expand = False, side = TOP)

checkupdate = Label(frame, text = "Looking for updates", font = ("Arial", 14))
checkupdate.pack()

try:
    link = "https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/version.txt"
    check = requests.get(link)
    
    if float(VERSION) < float(check.text):
        mb1 = messagebox.askyesno('Update Available', 'There is an update available. Click yes to update.')
        if mb1 is True:
            filename = os.path.basename(sys.argv[0])

            for file in os.listdir():
                if file == filename:
                    pass

                else:
                    os.remove(file)

            exename = f'NameOfYourApp{float(check.text)}.exe'
            code = requests.get("https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/NewUpdate.exe", allow_redirects = True)
            open(exename, 'wb').write(code.content)

            root.destroy()
            os.remove(sys.argv[0])
            sys.exit()
            
        elif mb1 == 'No':
            pass
        
    else:
        messagebox.showinfo('Updates Not Available', 'No updates are available')

except Exception as e:
    pass

Make sure you convert all the tkinter code to PyQt5 widgets. Also this is windows change the "https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/NewUpdate.exe" to "https://raw.githubusercontent.com/SomeUser/SomeRepo/main/SomeFolder/NewUpdate.app" for mac. If this does not work comment and I will try my best to convert this to PyQt5.

Dodu
  • 109
  • 2
  • 8