Differences between revisions 2 and 3
Revision 2 as of 2008-07-08 11:27:43
Size: 643
Editor: localhost
Comment: converted to 1.6 markup
Revision 3 as of 2009-08-14 20:41:48
Size: 698
Editor: ciphergoth
Comment:
Deletions are marked like this. Additions are marked like this.
Line 1: Line 1:
See also WhereAmI for another take on this problem.

See also WhereAmI for another take on this problem.

ThomasHeller posted this tip to the mailing list:

main_is_frozen() returns True when running the exe, and False when running from a script.

get_main_dir() returns the directory name of the script or the directory name of the exe - this is also sometimes useful.

   1 import imp, os, sys
   2 
   3 def main_is_frozen():
   4    return (hasattr(sys, "frozen") or # new py2exe
   5            hasattr(sys, "importers") # old py2exe
   6            or imp.is_frozen("__main__")) # tools/freeze
   7 
   8 def get_main_dir():
   9    if main_is_frozen():
  10        return os.path.dirname(sys.executable)
  11    return os.path.dirname(sys.argv[0])

HowToDetermineIfRunningFromExe (last edited 2009-08-14 20:41:48 by ciphergoth)