使用python固然方便,但不足之處是必須在本機安裝 python解釋器。如果本機沒有安裝python解釋器,而又要運行腳本,可以使用py2exe在安裝了python的機器上,將python腳本編譯成windows可執行文件,這樣就不需要python解釋器了。
windows | GUI |
console | 控制檯 |
service | windows服務 |
py2exe
下載地址
- http://www.py2exe.org
使用py2exe,首先要編寫一個編譯腳本,然後通過python運行編譯腳本即可將其他的腳本編譯成可執行文件。
MessageBox.py文件
#file:MessageBox.py
import win32api
import win32con
win32api.MessageBox(0,'hi!','python',win32con.MB_OK)
setup.py文件
#file:setup.py
import distutils
import py2exe
distutils.core.setup(windows=['MessageBox.py'])
運行方式
- 在windows命令行輸入"setup.py py2exe"
pyinstaller
下載地址
- http://www.pyinstaller.org/
運行方式
- 在pyinstaller的安裝目錄使用python pyinstaller.py --console --onefile mytest\Message.py【Message.py放在pyinstaller安裝目錄下新建的mytest下面】
- 生成的可運行文件在dist文件夾下