fix: Path handling across different operating systems

This commit is contained in:
Sebastian Fitt 2024-05-24 21:52:46 +02:00
parent 0a1749459d
commit 5e4bfadffa
2 changed files with 14 additions and 10 deletions

View File

@ -41,9 +41,11 @@ from one_euro_filter import OneEuroFilter
import psutil, os
import sys
from utils.misc_utils import resource_path
import platform
from pathlib import Path
frames = 0
models = Path("Models")
def run_model(input_queue, output_queue, session):
@ -70,10 +72,7 @@ class LEAP_C(object):
# Config variables
self.num_threads = 4 # Number of python threads to use (using ~1 more than needed to achieve wanted fps yields lower cpu usage)
self.queue_max_size = 1 # Optimize for best CPU usage, Memory, and Latency. A maxsize is needed to not create a potential memory leak.
if platform.system() == "Darwin":
self.model_path = resource_path("Models/leap123023.onnx") # funny MacOS files issues :P
else:
self.model_path = resource_path("Models\leap123023.onnx")
self.model_path = resource_path(models / 'leap123023.onnx')
self.low_priority = (
False # set process priority to low (may cause issues when unfocusing? reported by one, not reproducable)

View File

@ -2,6 +2,9 @@ import os
import typing
import sys
from pathlib import Path
from typing import Union
is_nt = True if os.name == "nt" else False
def PlaySound(*args, **kwargs): pass
@ -60,12 +63,14 @@ class FastMedian:
self.__median = lst_median(all, ordered=False)
return self.__median
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
def resource_path(relative_path: Union[str, Path]) -> str:
"""
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
base_path = Path(sys._MEIPASS)
except AttributeError:
base_path = os.path.abspath(".")
base_path = Path(".")
return os.path.join(base_path, relative_path)
return str(base_path / relative_path)