Created
July 9, 2022 22:03
-
-
Save hcosta/d33787d7ea0e92b0dca152345c5b5b87 to your computer and use it in GitHub Desktop.
Pyinstaller resources loading
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
import sys | |
import os | |
def resource_path(relative_path): | |
""" Get absolute path to resource, works for dev and for PyInstaller """ | |
try: | |
# PyInstaller creates a temp folder and stores path in _MEIPASS | |
base_path = sys._MEIPASS | |
except Exception: | |
base_path = os.path.abspath(".") | |
return os.path.join(base_path, relative_path) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment