Python 윈도우용 실행파일(exe) 만들기 (py2exe)

 
Notice : 해당 자료가 저작권등에 의해서 문제가 있다면 바로 삭제하겠습니다.
연구목적으로 사용하지 않고 악의적인 목적으로 이용할 경우 발생할 수 있는 법적은 책임은 모두 본인에게 있습니다.

Python 윈도우용 실행파일(exe) 만들기 (py2exe)

작성한 python 프로그램을 배포하는 방법에는 여러가지가 있지만,
Python이 설치되어 있지 않은 컴퓨터에서도 Python 프로그램을 실행하기 위한 방법중 py2exe 이용할 수 있다.(Windows 의 경우)

홈페이지는 http://www.py2exe.org/ 이며,

http://sourceforge.net/projects/py2exe/files/py2exe/0.6.9/ 에서 다운받아서 설치하면 된다.

Python GUI 프로그램 만들기(wxpython) 에서 만든 python 프로그램을 exe으로 만들어 보자

# -*- coding: utf-8 -*-
 
from distutils.core import setup
import py2exe
import glob
 
excludes = [
    "pywin",
    "pywin.debugger",
    "pywin.debugger.dbgcon",
    "pywin.dialogs",
    "pywin.dialogs.list",
    "win32com.server",
]

options = {
    "bundle_files": 1,                    # create singlefile exe
    "compressed"  : 1,                 # compress the library archive
    "excludes"    : excludes,
    "dll_excludes": ["w9xpopen.exe", "MSVCP90.dll"]   # we don't need this
}

setup(
    options = {"py2exe": options},
    zipfile = None,                    # append zip-archive to the executable
    #console = ["apollo_image.py"],
    windows = ["apollo_image.py"],
    data_files=[("images",glob.glob("images/*"))]
)

실행

python apollo_image_setup.py py2exe

생성된 디렉토리 구조는 아래와 같다.

tree
├─build
│  └─bdist.win32
│      └─winexe
│          ├─bundle-2.7
│          ├─collect-2.7
│          │  ├─encodings
│          │  ├─logging
│          │  ├─unittest
│          │  └─wx
│          └─temp
├─dist
│  ├─images
│  │  └─apollo.bmp
│  └─apollo_image.exe
├─images
│  └─apollo.bmp
├─apollo_image.py
└─apollo_image_setup.py

실제로 배포할때는 dist 폴더의 이름을 바꿔서 zip으로 묶어 배포하면 된다.

참고 : http://cshong.tistory.com/350

 

This entry was posted in Python/Ruby/Perl and tagged , . Bookmark the permalink.

댓글 남기기