Created
August 24, 2023 02:27
-
-
Save quietcricket/009590ffa40eb22855751a87d93b7740 to your computer and use it in GitHub Desktop.
pyinstaller can package a python app into a single executable file. When this executable file runs, it's first extracted into a temporary location then the python script is called. The usual loading of files with relative path would not work. The following code is found online to work around this issue.
This file contains hidden or 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 abspath(filename): | |
# looking for magic word _MEIPASS | |
bundle_dir = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__))) | |
return os.path.abspath(os.path.join(bundle_dir, filename)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment