Python是一個強大的工具,可惜不是每個人的計算機裡面都有安裝。當您寫了一個好用的工具。要如何讓那些沒有安裝Python的人使用你的工具呢?
對於這樣一個需要standalone exectuable環境的需求,直到撰寫經驗為止,只看到兩個比較好用且有持續維護的套件。一個是py2exe。另外一個就是本經驗要介紹的PyInstaller。
工具/原料
PyInstaller
Python
PyInstaller安裝
下載地址:
最新版本:PyInstaller 2.0
直接“解壓縮”之後即可使用,解壓到您想讓他在的路徑即可
PyInstaller配置
事先寫好py程式
在命令列執行:python Makespec.py --console --onefile NotePad\notepad.py
報錯:Configfile is missing or unreadable. Please run Configure.py before building
在命令列執行:Configure.py
報錯:Python 2.6+ on Windows support needs pywin32,Please install
安裝最新版本的 pywin32-217.win32-py2.7.exe,下載地址:
PyInstaller使用
命令列中執行
目錄切換到PyInstaller的安裝目錄“E:\pyinstaller-1.5\pyinstaller-1.5>”
在PyInstaller的安裝目錄下新建一個資料夾(比如NotePad), 然後將要轉換的py指令碼放到資料夾裡(notepad.py)
E:\pyinstaller-1.5\pyinstaller-1.5>python Makespec.py --console --onefile NotePad\notepad.py
E:\pyinstaller-1.5\pyinstaller-1.5>python Build.py NotePad\notepad.spec
驗證exeE:\pyinstaller-1.5\pyinstaller-1.5>
E:\pyinstaller-1.5\pyinstaller-1.5\NotePad\dist\notepad.exe 0 0 100(成功)
檢視生成的檔案,生成的中間檔案spec
檢視生成的檔案,生成的最終檔案exe
注意事項
在轉換之前要確保py程式可以正常通過
如果轉換過程中出現什麼錯誤,用搜索引擎搜尋解決一下