1

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?

bigcat42
  • 247
  • 2
  • 7

2 Answers2

2
  • 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)

Joran Beasley
  • 110,522
  • 12
  • 160
  • 179
  • I was looking at ways to do this using a self-deleting batch file. Unfortunately Windows doesn't have "Sleep" command across all versions. I found [this workaround for batch files](http://stackoverflow.com/questions/1672338/how-to-sleep-for-5-seconds-in-windowss-command-prompt-or-dos), but I don't know how to pull that off in a one-line command. – bigcat42 Mar 28 '14 at 13:41
1

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.

Heikki Toivonen
  • 30,964
  • 11
  • 42
  • 44
  • I like this, nice and simple. Different file names would cause problems if the user wants to use a shortcut to the program, but maybe there's no reason for shortcuts with a one file program. – bigcat42 Mar 27 '14 at 19:24