PyInstaller » 이력 » 버전 2
이태훈, 2025/01/27 06:37
| 1 | 1 | 이태훈 | h1. PyInstaller |
|---|---|---|---|
| 2 | |||
| 3 | h3. 1. cmd를 관리자 권한으로 실행 |
||
| 4 | |||
| 5 | !clipboard-202501271321-jserb.png! |
||
| 6 | |||
| 7 | h3. 2. 명령어 입력 |
||
| 8 | |||
| 9 | <pre> |
||
| 10 | -- 프로그램 설치 |
||
| 11 | pip install pyinstaller |
||
| 12 | |||
| 13 | -- exe파일 만들기 |
||
| 14 | pyinstaller 파일명.py |
||
| 15 | |||
| 16 | -- 콘솔창 제거(-w OR --windowed) |
||
| 17 | pyinstaller -w 파일명.py |
||
| 18 | |||
| 19 | -- 실행파일 하나만 생성(-F 또는 –onefile) |
||
| 20 | pyinstaller -F 파일명.py |
||
| 21 | </pre> |
||
| 22 | 2 | 이태훈 | |
| 23 | h3. 3. 리소스가 포함된 exe 파일 생성 |
||
| 24 | |||
| 25 | [코드 추가] |
||
| 26 | |||
| 27 | <pre> |
||
| 28 | import sys |
||
| 29 | import os |
||
| 30 | |||
| 31 | def resource_path(relative_path): |
||
| 32 | """ Get absolute path to resource, works for dev and for PyInstaller """ |
||
| 33 | try: |
||
| 34 | # PyInstaller creates a temp folder and stores path in _MEIPASS |
||
| 35 | base_path = sys._MEIPASS |
||
| 36 | except Exception: |
||
| 37 | base_path = os.path.abspath(".") |
||
| 38 | return os.path.join(base_path, relative_path) |
||
| 39 | </pre> |
||
| 40 | |||
| 41 | [실행파일 생성 명령어] |
||
| 42 | |||
| 43 | <pre> |
||
| 44 | pyinstaller -w -F -i="파비콘.ico" --add-data="ui파일명.ui;./" --add-data="파비콘.ico;./" 파일명.py |
||
| 45 | </pre> |