Skip to content

Instantly share code, notes, and snippets.

@stlehmann
Created March 28, 2014 06:55
Show Gist options
  • Save stlehmann/9826831 to your computer and use it in GitHub Desktop.
Save stlehmann/9826831 to your computer and use it in GitHub Desktop.
Determine the application path of a Python EXE
def app_path():
"""
Return the path of the application.
"""
if getattr(sys, 'frozen', False):
return os.path.dirname(sys.executable)
return os.path.dirname(__file__)
@stlehmann
Copy link
Author

This code is very useful for getting the path of the application if py2exe or PyInstaller have been used to generate a Python EXE. Because file is empty in such a case you need to check if the application is running as a script or as a frozen exe. So that is what the app_path function is doing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment