Skip to content

Instantly share code, notes, and snippets.

@hcosta
Created July 9, 2022 22:03
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hcosta/d33787d7ea0e92b0dca152345c5b5b87 to your computer and use it in GitHub Desktop.
Save hcosta/d33787d7ea0e92b0dca152345c5b5b87 to your computer and use it in GitHub Desktop.
Pyinstaller resources loading
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