4

I have a small Python program I am making available as a py file, but also as a standalone pyz and exe (via pyinstaller) files, which contain all dependencies.

When displaying licence information in the pyz or exe, I need to include extra statements regarding the dependencies I'm including.

How can I differentiate if the program is running as a py, pyz, or exe in order to display difference licences?

.

I've found this response to a different question, which may help for the exe: https://stackoverflow.com/a/404750/36061

    if getattr(sys, 'frozen', False):
        print(EXE_LICENCE)
    else:
        print(NORMAL_LICENCE)
masher
  • 3,814
  • 4
  • 31
  • 35

1 Answers1

1

Put together a couple of checks. The first checks if it is running as a pyinstaller exe. The second (taken from comment on OP) if it was a pyz. And then the default.

    if getattr(sys, 'frozen', False):
        print(EXE_LICENCE)
    elif __loader__.__module__ == 'zipimport':
        print(PYZ_LICENCE)
    else:
        print(NORMAL_LICENCE)
masher
  • 3,814
  • 4
  • 31
  • 35