메모장

Pyinstaller: Python 실행 파일 만들기

kn 2022. 1. 20. 22:23

Pyinstaller 는 파이썬 코드를 실행 파일 (.exe) 로 변환해 주는 라이브러리다. 변환된 exe 파일은 실행에 필요한 모든 라이브러리를 포함하여 파이썬이 설치되지 않은 환경에서도 실행 가능하다. 파이썬 설치가 용이하지 않은 환경에 배포할 수 있는 좋은 방법이다.

 

1. Pyinstaller 설치

pip install pyinstaller

 

2. Auto PY to EXE

auto-py-to-exe 를 통해 쉽게 pyinstaller를 사용할 수 있다.

pip install auto-py-to-exe

 

3. 사용방법

# auto py to exe 실행
auto-py-to-exe

 

auto py to exe
Auto Py To Exe 메뉴

메뉴 설명
- Script Location
  > .py 파일 위치
- Onefile
  > 실행 파일 개수
- Console
  > exe 파일 실행 시 콘솔 표기 유무
- Additional Files
  > 의존 라이브러리 파일 위치, 필요 시 설정

- CONVERT .PY TO .EXE
  > 실행 시 pyinstaller command 가 자동으로 설정되고 output 파일이 생성된다.

 

CONVERT .PY TO .EXE 실행 결과

4. TIP

: Anaconda 환경에서는 실행 파일이 잘 만들어지지 않는다. vanila python을 사용하자.
: https://www.python.org

: PyQt5 를 사용해 GUI 를 만들 수 있다.
: https://wikidocs.net/book/2165

 

5. 라이브러리에 따른 Additional Files 필요 유무

라이브러리 Additional Files 필요 유무
PyQt5 X
Matplotlib O
Scikit-Learn O