PyInstaller
파이썬 파일을 exe파일로 만들 수 있는 모듈
exe파일로 만들면 파이썬이 설치되어 있지 않은 pc에서도 프로그램을 실행할 수 있도록 해준다.
공식 홈페이지:
PyInstaller Quickstart — PyInstaller bundles Python applications
PyInstaller freezes (packages) Python applications into stand-alone executables, under Windows, GNU/Linux, Mac OS X, FreeBSD, Solaris and AIX. PyInstaller’s main advantages over similar tools are that PyInstaller works with Python 3.5—3.9, it builds sm
www.pyinstaller.org
PyInstaller 설치
1. 명령 프롬프트에서 pip install pyinstaller로 설치
2. JupyterNotebook환경의 경우 !pip install pyinstaller 로 설치가능
PyInstaller 실행 방법
ex) hellopython.py 라는 파일을 예로 든다.
def hello(name,word):
name = name
word = word
print("\n{}, {}".format(name, word))
inputname = input("이름을 입력해 주세요: ")
inputword = input("하고 싶은 말을 입력해 주세요: ")
hello(inputname,inputword)
이름을 입력해 주세요: 파이썬
하고 싶은 말을 입력해 주세요: 잘 있지?
파이썬, 잘 있지?
0. JupyterNotebook환경일 경우 ipynb 파일을 py파일로 먼저 변환시켜준다. (변환방법은 각자 알아서..)
1. 명령 프롬프트를 이용해 hellopython.py 파일이 있는 폴더로 이동한다. (필자는 pyinstaller_sample이란 폴더를 생성해서 그 안에 hellopython.py라는 파일을 만들었다.)
2. pyinstaller hellopython.py 를 실행시키고 만들어진 폴더 중 dist 폴더로 이동하면 exe파일과 다른 폴더들을 찾아 볼 수 있다.
3. 콘솔창을 출력되지 않도록 하려면 명령어에 '-w' 또는 '--windowed'를 추가해 준다. 단 지금 예제는 콘솔창 외에 대체할 ui가 없음으로 에러 발생.
예) pyinstaller -w hellopython.py or pyinstaller --windowed hellopython.py
4. 실행파일 하나만 생성하기 위해서는 명령어네 '-F' 또는 '-onefile'을 추가해 준다.
예) pyinstaller -F hellopython.py or pyinstaller -onefile hellopython.py
5. -F 옵션을 주고 파일 하나로 생성 한 경우 프로그램 실행 속도가 -F 옵션을 주지 않은 것보다 상당히 느려진다고 한다.
'AI > Python Module' 카테고리의 다른 글
Python #KoNLPy (0) | 2021.10.19 |
---|---|
PyAutoGUI #파이썬 마우스 키보드 이벤트 제어 (0) | 2021.10.17 |
Module #matplotlib, #urllib, #BeautifulSoup (0) | 2021.07.26 |
Module #sklearn (0) | 2021.07.26 |
Module #pandas (0) | 2021.07.26 |