2012年12月14日 星期五

Python 執行檔產生方式

之前使用過py2exe 去產生 python 程式的 單一執行檔(click here),後來我安裝了pythonxy 去開發GUI 程式,我程式有用到 Enthought 的Traits UI/Traits 套件,雖然開發GUI 程式很快,我也從中學到MVC 的概念,不過我想要用 py2exe 去產生有引用 Traits UI/Traits 的執行檔時,一直無法成功,enthought 也回答我的疑問,我是有看沒有懂,所以只好去另找方法後來,
用Python 科學計算中文版 問了作者,他介紹與教我 用 bbfreeze 去產生執行檔,這個bbfreeze 產生的東西,應該算是建立一個環境給你寫的程式執行,所以會產生一個很大的Folder,不過可以用就好。


以下介紹方法:
1.bbfreeze 的setup 寫法:
#This script is for bbfreeze
#It generate execute file.
#Usage : python setup.py


from bbfreeze import Freezer
f = Freezer("Base64gui-1.0")
f.addScript("base64gui.py",gui_only=True)
f() # starts the freezing process




2.py2exe 要引用pyqt4 的setup 寫法:
#This script is for py2exe module
#It generate execute file.
#Usage : python setup.py py2exe




from distutils.core import setup
import py2exe
setup(windows=[{"script" : "d:/base64gui/py2exe/findandreplacedlg.py"}], options={"py2exe" : {"includes" : ["sip", "PyQt4"]}})

-----2012/12/14 update --------
另一個 產生 stand-alone executables 工具- PyInstaller  (我測試的OS 是 windows xp)
要先裝 pywin32,使用方法
python pyinstaller.py yourpgm.py
它會產生 yourpgm folder,理面有個 dist 目錄 ,就會找到 yourpgm.exe 檔

2012年12月11日 星期二

MongoDB 筆記

MongoDB 筆記