ทำ .py ให้เป็น exe

  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.
  • warning: realpath() [function.realpath]: SAFE MODE Restriction in effect. The script whose uid is 1005 is not allowed to access /tmp owned by uid 0 in /var/www/sites/sugree/codenone.com/subdomains/www/html/includes/file.inc on line 190.

ช่วยสอนวิธีการทำ .py ให้เป็น exe หน่อยครับ
คือว่ามันยากตรงที่งานของผมมันเกี่ยวข้องกับ module อื่นด้วยครับ คือ
PyOpenGL
PyODE
PyGame
ขอบคุณครับ

sugree's picture

ปกติผมใช้ py2exe ครับ แล้วก็มาเขียน winsetup.py คล้ายๆ ข้างล่าง มันดีตรงที่ถ้าเราเขียนแบบปกติ มันจะหา dependencies ทั้งหมดให้เอง ถ้าเขียนแบบแปลก เช่น พวก dynamic import ก็ระบุให้รวมเข้าไปด้วย

#!/usr/bin/env python
 
# Written by Bram Cohen
# see LICENSE.txt for license information
 
import setup
del setup
 
from distutils.core import setup
import py2exe
 
opts = {
    "py2exe": {
    "includes": "encodings,encodings.*,"
                "BitQueue.launchmanycore_bittorrent,"
                "BitQueue.launchmanycore_bittornado,"
                "Zeroconf,"
                "pywin,pywin.*",
    "excludes": "pango,atk,gobject,pywin,pywin.*,Tkconstants,Tkinter,tcl",
    "dll_excludes":["iconv.dll", "intl.dll", "libatk-1.0-0.dll",
                    "libgdk_pixbuf-2.0-0.dll", "libgdk-win32-2.0-0.dll",
                    "libglib-2.0-0.dll", "libgmodule-2.0-0.dll",
                    "libgobject-2.0-0.dll", "libgthread-2.0-0.dll",
                    "libgtk-win32-2.0-0.dll", "libpango-1.0-0.dll",
                    "libpangowin32-1.0-0.dll",
                    ],
    }
}
if 1:
    try:
        import modulefinder, sys
        import win32com
        for p in win32com.__path__[1:]:
            modulefinder.AddPackagePath("win32com", p)
        for extra in ["win32com.shell"]: #,"win32com.mapi"
            __import__(extra)
            m = sys.modules[extra]
            for p in m.__path__[1:]:
                modulefinder.AddPackagePath(extra, p)
    except ImportError:
        # no build path setup, no worries.
        pass
 
setup(
      console = [ {'script': 'btqueue.py',},
                  {'script': 'btmakemetafile.py',},
                  {'script': 'btsethttpseeds.py',},
                  {'script': 'btshowmetainfo.py',},
                ],
      service = ["btqsvc"],
      options = opts,
     )

โค้ดนี้ผมนำมาจาก BitTorrent มาแก้เพิ่มครับ (ใส่สีแล้ว)

pittaya's picture

ลองดูโค้ดของ Frets on Fire ดูครับ
อันนั้นเค้าก็เป็น python + pyOpenGL
ทำเป็น binary รันได้หลาย platform

ใช้อย่างไรครับ งง

ย้าย Codenone

ประกาศย้าย Codenone ไปใช้ Forum ของ Blognone แทนครับ ตามไปตั้งกระทู้ต่อได้ที่ Codenone Forum (รายละเอียดอ่านจากกระทู้ ย้าย Codenone ไปรวมกับ Blognone)

กระทู้เก่าๆ จะย้ายตามไปในภายหลัง ตอนนี้ปิดการโพสต์กระทู้ไว้ เหลือไว้เฉพาะอ้างอิงเท่านั้น