2

I've got ready, already compiled python application for windows but there is a problem with making an installer, which creates desktop icon for it when you check a corresponding mark.

I made an installer using clean NSIS script, fbs and pynsist. Actually, there is no problem to create an installer which downloads your app to Program Files but however I haven't found the way to create an icon which will be shown on desktop.

Any help is appreciated.

Tymofii Koval
  • 153
  • 1
  • 8
  • Possible duplicate of [Is it possible to create shortcuts into a specific directory in python?](https://stackoverflow.com/questions/32154767/is-it-possible-to-create-shortcuts-into-a-specific-directory-in-python) – Robert Kearns Sep 25 '19 at 19:30
  • What does your installer.cfg look like? – Anders Sep 26 '19 at 19:57

1 Answers1

4

Pynsist does not seem to have a way to inject extra code for some reason but you can override the entire install script.

Make a copy of your pyapp.nsi file (or grab it from Github).

There are two places in the file where it does CreateShortCut "$SMPROGRAMS\..... Add another line under it with:

CreateShortcut "$DESKTOP\[[scname]].lnk" "[[sc['target'] ]]" '[[ sc['parameters'] ]]' "$INSTDIR\[[ sc['icon'] ]]"

And finally, in your installer.cfg file, add/set

[Build]
nsi_template=c:\my_custom_pyapp.nsi
Anders
  • 97,548
  • 12
  • 110
  • 164
  • 1
    The nsi template file is actually a way to inject extra code, though the details aren't really documented. It uses Jinja templating, which allows for inheriting from a parent template and extending blocks defined there. E.g. you could extend the `install_shortcuts` block. `[[ super() ]]` inserts the contents of the block from the parent template. – Thomas K Sep 27 '19 at 07:16
  • 2
    @ThomasK Feel free to edit my answer or add your own. – Anders Sep 27 '19 at 10:09
  • Unfortunately, running my `installer.cfg` gives me jinja's `TemplateNotFoundError`. I've done everything you asked me to do. Should my installer work anyway or is there something I should edit? – Tymofii Koval Sep 28 '19 at 17:49
  • @TimKoval Well, you need to change "c:\my_custom_pyapp.nsi" to where you saved the .nsi. – Anders Sep 28 '19 at 18:05
  • 1
    @ThomasK thanks for the hint, took me a while how to get it to work, here it is for future generations https://gist.github.com/janmechtel/16d0536e81fd5da93acd731341abc5a5 – Cilvic Aug 31 '20 at 20:37