PYTHON

파이썬 강의 노트 1 – 나도코딩

 

 

  1. 파이썬 프로그램을 .exe 실행 파일로 만드는 방법 (PyInstaller)

 

 


 

1. 파이썬 프로그램을 .exe 실행 파일로 만드는 방법 (PyInstaller)

 

https://www.youtube.com/watch?v=Es1fQqqxIFQ

 

# pyinstaller 설치
pip install pyinstaller

 

# pyinstaller add folder with images in exe file
https://stackoverflow.com/questions/51264169/pyinstaller-add-folder-with-images-in-exe-file

 

# 상대경로를 받아서 절대경로를 반환

import os

def resource_path(relative_path):
    try:
        base_path = sys._MEIPASS
    except Exception:
        base_path = os.path.abspath(".")

    return os.path.join(base_path, relative_path)

 

# 그림 파일을 절대 경로로 지정해야한다.
resource_path(“gui_basic\img.png”)

 

# 와일드 카드로 한번에 그림 파일을 지정
pyinstaller -w –add-data ‘.\gui_basic\*.png;gui_basic’ -F .\gui_basic\3_label.py

 

# 그림 파일을 각각 지정
pyinstaller -w –add-data ‘.\gui_basic\img.png;gui_basic’ –add-data ‘.\gui_basic\img2.png;gui_basic2’ -F .\gui_basic\3_label.py

 

# –add-data ‘그림파일 위치;결과 파일에서의 그림 파일 위치’

 

Related posts

Leave a Comment