Get the absolute path of the resource file
(relative_path)
| 2 | import sys |
| 3 | |
| 4 | def get_absolute_path(relative_path): |
| 5 | """Get the absolute path of the resource file""" |
| 6 | try: |
| 7 | # Packaged environment |
| 8 | base_path = sys._MEIPASS |
| 9 | # Adapt to _internal directory for PyInstaller 6.0 and above |
| 10 | internal_path = os.path.join(base_path, '_internal') |
| 11 | if os.path.exists(os.path.join(internal_path, relative_path)): |
| 12 | base_path = internal_path |
| 13 | except Exception: |
| 14 | # Development environment |
| 15 | base_path = os.path.abspath(".") |
| 16 | return os.path.join(base_path, relative_path) |