Python

Compile

exe로 컴파일 (pyinstaller 이용) - Resource 추가

홍사훈     0건     220회

본문

-F옵션을 사용하여 컴파일시 단일 이미지 삽입


##  test.py 작성

  def resource_path(relative_path): 

      try:

          # PyInstaller에 의해 임시폴더에서 실행될 경우 임시폴더로 접근하는 함수

          base_path = sys._MEIPASS

      except Exception:

          base_path = os.path.abspath(".")

 

      return os.path.join(base_path, relative_path)

    :

    :

  imgpath = resource_path('sahoon.png')

  img = tkinter.PhotoImage(file=imgpath)

  label=tkinter.Label(window, image=img)

  label.place(x=900, y=5)


## test.py 컴파일

  d:\python> python.exe pyinstaller.exe -w -F --add-data "sahoon.png;." test.py

 

 

참고- https://babysunmoon.tistory.com/entry/pyinstaller-%EC%9D%B4%EB%AF%B8%EC%A7%80-%EC%B6%94%EA%B0%80

-아이콘 삽입 (미 확인) 

​>pyinstaller --icon=unnamed_Lsk_icon.ico --onefile ./helloworld.py 

등록된 댓글이 없습니다.



Copyrightⓡ1996~2025, sahoon.com All Rights Reserved.