feat(source): 增加对 Nuitka 打包的支持

- 修改 resource_path 函数以支持 Nuitka 打包环境
- 更新 .gitignore 文件
This commit is contained in:
hyb-oyqq
2025-07-16 14:36:27 +08:00
parent 4ec2b4ab5c
commit fc70b9c958
2 changed files with 13 additions and 6 deletions

3
.gitignore vendored
View File

@@ -170,4 +170,5 @@ cython_debug/
# PyPI configuration file
.pypirc
nuitka-crash-report.xml
nuitka-crash-report.xml
build.bat

View File

@@ -25,11 +25,17 @@ import sys
import os
def resource_path(relative_path):
"""获取资源的绝对路径适用于开发环境和PyInstaller打包环境"""
try:
# PyInstaller创建的临时文件夹
base_path = sys._MEIPASS # type: ignore
except Exception:
"""获取资源的绝对路径,适用于开发环境和Nuitka/PyInstaller打包环境"""
if getattr(sys, 'frozen', False):
# 如果是打包后的环境Nuitka或PyInstaller
if hasattr(sys, '_MEIPASS'):
# PyInstaller的临时路径
base_path = sys._MEIPASS # type: ignore
else:
# Nuitka的路径或PyInstaller --onefile模式
base_path = os.path.dirname(sys.executable)
else:
# 开发环境
base_path = os.path.dirname(os.path.abspath(__file__))
return os.path.join(base_path, relative_path)