개발 모음집/Python

[Python] pyinstaller 실행파일 생성

wonos 2021. 2. 21. 19:04
# test.py
import datetime 
if __name__ == "__main__" : 
	print("Start.") 

	cur_time = datetime.datetime.now() 
	print("Current time : %s" % cur_time) 

	print("End.")

pyinstaller 설치

  • pip install pyinstaller

exe 파일 만들기

  • test.py가 있는 디렉토리로 이동하여, pyinstaller 명령어를 입력해줍니다.
    • 참고로 --onefile 이라는 옵션을 넣어주면, 하나의 실행파일로 생성이 됩니다. (참고로, --noconsole 옵션을 넣어주면 콘솔창이 뜨지 않고 실행이 됩니다.)
    • 명령어를 실행하면, 이와같이 dist, build 등 여러개의 파일이 생성됩니다.
    • dist 폴더로 들어가보면, 아래와 같이 실행파일(test.exe)이 생성된것을 확인 할 수 있습니다.
  • pyinstaller --onefile test.py
  • 실행파일에 이미지 넣기
    • pyinstaller --icon=test.ico --onefile test.py