- 파이썬 script 소스 코드를 *.exe 실행 파일 로 변환하는 방법 (convert py to exe)

python 빌드, python build, 파이썬 빌드

//-------------------------------------
    - pyinstaller 설치
pip install pyinstaller

    - 실행 파일로 만들기
pyinstaller --onefile hello.py
        - 만들어진 hello.exe 실행에 3초 정도 걸림


    --onefile 옵션

- 사용시 : 실행파일을 1개 파일로 만들수 있지만 크기가 기본 45M, 실행시간 3초에 백신프로그램 실행중일때 8초까지 갈수 있다.

- 미사용시 : _internal 이라는 130M짜리 폴더(4,325개 파일)가 생기지만 실행시간이 빠르다.

 


    - 생성된 실행파일이 다른 모듈 의존도가 낮음
> dumpbin /dependents hello.exe
    KERNEL32.dll
    ADVAPI32.dll


//-------------------------------------
pi2exe
http://www.py2exe.org/
https://github.com/py2exe/py2exe


    - py2exe 설치
pip install py2exe


    - 스크립트 실행 파일로 만들기
https://www.py2exe.org/index.cgi/Tutorial

    - hello.py
print "Hello World!"

    - setup.py 파일 생성

from distutils.core import setup
import py2exe, sys, os

sys.argv.append("py2exe")

setup(
    options={"py2exe": {"bundle_files": 1, "compressed": True}},
    windows=[{"script": "hello.py"}],
    zipfile=None,
)




    - exe 만들기
python setup.py py2exe
        - 만들어진 hello.exe 실행에 2초 정도 걸림


    - 생성된 실행파일이 다른 모듈 의존도가 높음
> dumpbin /dependents hello.exe
    USER32.dll
    SHELL32.dll
    KERNEL32.dll
    VCRUNTIME140.dll
    api-ms-win-crt-string-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-convert-l1-1-0.dll
    api-ms-win-crt-environment-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll
    api-ms-win-crt-utility-l1-1-0.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-math-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll


//-------------------------------------

https://github.com/python/cpython

//-------------------------------------
https://stackoverflow.com/questions/5458048/how-can-i-make-a-python-script-standalone-executable-to-run-without-any-dependen

반응형
Posted by codens