py2exe is a Python Distutils extension which converts Python scripts into executable Windows programs, able to run without requiring a Python installation.
1. 在專案資料夾建立 setup.py
from distutils.core import setup
import py2exe
setup(console=['main.py']) # main.py 為你的主程式名稱
2. 執行 C:\Python27\python.exe setup.py py2exe
有可能會出錯, 官網說
You must make py2exe copy the three dlls and the manifest file into your
project's dist directory, in a subdirectory called
'Microsoft.VC90.CRT'. To achieve this, add a data_files option to your
project's setup.py:
dist | +-Microsoft.VC90.CRT | | | +-Microsoft.VC90.CRT.manifest | +-msvcm90.dll | +-msvcp90.dll | +-msvcr90.dll | |-etc
我下載 msvcp90.dll 放入專案資料夾也可以
3. 建立完的執行檔包會在專案資料夾的 dist, 發佈時要整個 dist 一起打包
Reference :
沒有留言:
張貼留言