Python

Compile

exe로 컴파일 (pyinstaller 이용) - module 추가/제외

홍사훈     0건     540회

본문

모듈추가

 

보통은 스크립트 안에 import한 모듈은 자동으로 추가되는데, 간혹 추가되지 못하고, 컴파일된 실행파일을 실행하면 다음과 같은 오류가 나타날 때가 있다.

[Error case : No module named ~~  

 

● pyinstaller 업데이트

  c:\python> pip install --upgrade pyinstaller

● --hidden-import 옵션 이용

단일 모듈 추가

  c:\python> pyinstaller pyscript.py --hidden-import=my_module

다중 모듈 추가 : --hidden-import 옵션을 계속 써서 추가할 수 있다.

  c:\python> pyinstaller pyscript.py --hidden-import=my_module1, --hidden-import=my_module2

● hooks 파일 추가

다음을 작성후, Python폴더 (\python\Lib\site-packages\PyInstaller\hooks)로 복사한다.

hook-모듈이름.py

from PyInstaller.utils.hooks import collect_all 

datas, binaries, hiddenimports = collect_all('모듈이름')

 

● 모듈 제외 --exclude 옵션 이용

단일 모듈 제외

  c:\python> pyinstaller pyscript.py --exclude module

 

 

 

등록된 댓글이 없습니다.



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