Python script into a standalone single file executable that can auto-update?

1.3k Views Asked by At

I wrote a program in Python 2.7 for my office. Using PyInstaller with the --onefile flag, I've compiled it into a single EXE file to distribute to my co-workers. What I'm trying to figure out now is how to supply updates automatically but still keep the program as a single file.

My current method is to have the program alert the user of a new version and give instructions where to obtain the updated file. This works, but I want to find some method of updating without the user's involvement.

I am aware of Esky, which can create auto-updating Python programs, but as far as I can tell, it requires the program to exist as multiple files.

Any suggestions on how I make a standalone, single file EXE python program that can auto-update?

2

There are 2 best solutions below

1
On BEST ANSWER
  • you can download your new executable to a temp folder
  • use __file__ to know the current location of the executable
  • show a message that you need to restart
  • use sys.execcv or subrocess alternative to replace the current running process with a small script something like

    "sleep(1) & copy {tempfile} {filename}".format(tmp_file,__file__)

(simple batch commands that overwrite the old exe with the new exe)

1
On

When your application has alerted user of a new version and user has said they want it, download the new exe, start the new exe, and shut down current exe. The new exe should remove any old exes it sees around. The different versions need to be named differently.