Created
March 28, 2014 06:55
-
-
Save stlehmann/9826831 to your computer and use it in GitHub Desktop.
Determine the application path of a Python EXE
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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__) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.