properly implement resource finding for nuitka

This commit is contained in:
Roland W-H 2025-04-27 15:28:10 +01:00
parent 7cb41652b4
commit 2422395759
2 changed files with 20 additions and 8 deletions

View File

@ -1,5 +1,5 @@
## Nuitka compilation options ## Nuitka compilation options
# nuitka-project: --mode=standalone # nuitka-project: --mode=onefile
# nuitka-project: --enable-plugin=pyqt6 # nuitka-project: --enable-plugin=pyqt6
# nuitka-project: --include-module=widgets.mpl_widget # nuitka-project: --include-module=widgets.mpl_widget
# nuitka-project: --include-data-files=icon2.ico=icon2.ico # nuitka-project: --include-data-files=icon2.ico=icon2.ico

View File

@ -2,12 +2,24 @@ import os.path
import sys import sys
# If using PyInstaller, use it's temporary path, otherwise use cwd # Returns the correct path for Nuitka onefile mode, standalone mode or normal Python
# Credit: https://stackoverflow.com/questions/7674790/bundling-data-files-with-pyinstaller-onefile/13790741#13790741 # Credit: https://nuitka.net/user-documentation/common-issue-solutions.html#onefile-finding-files
def get_res_path(relative_path): def get_res_path(relative_path):
try: path_a = ""
base_path = sys._MEIPASS
except AttributeError:
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path) try:
path_a = os.path.join(sys.__compiled__.containing_dir, relative_path)
except AttributeError:
pass
path_b = os.path.join(os.path.dirname(__file__), relative_path)
path_c = os.path.join(os.path.dirname(sys.argv[0]), relative_path)
if os.path.isfile(path_a):
return path_a
elif os.path.isfile(path_b):
return path_b
elif os.path.isfile(path_c):
return path_c
else:
return os.path.join(os.path.abspath("."), relative_path)