pyinstall 打包pyqt 静态资源
def resource_path(relative_path):
"""获取打包后的资源文件路径"""
if hasattr(sys, '_MEIPASS'):
# 打包后的路径
base_path = sys._MEIPASS
else:
# 开发阶段的路径
base_path = os.path.abspath(".")
return os.path.join(base_path, relative_path)
# 使用示例
icon_path = resource_path("icons/icon.png")
打包参数
pyinstaller --windowed --noconfirm --add-data "icons:icons" -F main.py