본문 바로가기

개발/Python

UI 파일 Pyinstaller 로 묶어서 배포하기

반응형

QtDesinger 로 UI 를 제작 후 Pyinstaller 로 배포 시 UI 를 불러오지 못하는 오류가 발생할때 UI 파일을 포함하여 배포하는 방법

 

소스코드

def resource_path(relative_path):
    """ Get absolute path to resource, works for dev and for PyInstaller """
    base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
    return os.path.join(base_path, relative_path)


uiForm = resource_path("testui.ui")
ui = uic.loadUiType(uiForm)[0]

 

Spec 파일 생성

pyi-makespec --noconsole --onefile testui.py

 

Spec 파일 수정

testui.spec 파일에 QtDesigner 로 생성한 ui 파일의 경로를 added_files 변수로 지정

더보기

block_cipher = None
added_files = [('testUI1.ui', '.'), ('testUI2.ui', '.'), ('testUI3.ui', '.')]

 

a = Analysis(['D:\\Workspace\\Python\\testui.py'],
             pathex=['D:\\Workspace\\Python'],
             binaries=[],
             datas=added_files,

added_files 를 리스트로 묶어서 datas 에 변수로 지정해 준다.

 

Pyinstaller 로 배포

testui.spec 파일을 Pyinstaller 파일로 배포한다

더보기

pyinstaller --clean testui.spec

반응형

자바스크립트를 허용해주세요.
[ 자바스크립트 활성화 방법 ]
from Mohon Aktifkan Javascript!