一、軟件準備python
cx_Freeze-4.3.win32-py3.2.msi --打包用ide
PySide-1.2.2.win32-py3.2.exe --跨平臺用,QT測試
python-3.2.4.msi --解析器ui
pywin32-217.win32-py3.2.exe --支持win32平臺編碼
二、遇到問題spa
Python執行exe程序時出現報錯,由於cmd爲utf-8,而python要求unicode,因此要先切換回unicode,我這裏試了下:命令行
切換cmd到中文編碼格式:chcp 936code
活動代碼頁: 936 C:\Users\tao>G:\Svn\Tool\Python\Hello\build\exe.win32-3.2\hello.exe 系統找不到指定的路徑。 C:\Users\tao>G:\Svn\Tool\Python\Hello\build\exe.win32-3.2\hello.exe hello C:\Users\tao>G:\Svn\Tool\Python\Hello\build\exe.win32-3.2\hello.exe hello C:\Users\tao>z
還有cmd 命令行執行Python時出現問題:blog
報錯,後面新增環境變量:ip
PYTHONIOENCODING
utf-8
運行python就OK了;
不能刪除,應該是python運行時要切換到utf-8
後面這步能夠刪除,可是cmd的編碼方式統一改爲:
regedit
基本就這些了,須要注意的;
例子代碼:--測試用
hello.py
import datetime import sys print ("hello")
setup.py
# A very simple setup script to create a single executable # # hello.py is a very simple "Hello, world" type script which also displays the # environment in which the script runs # # Run the build process by running the command 'python setup.py build' # # If everything works well you should find a subdirectory in the build # subdirectory that contains the files needed to run the script without Python from cx_Freeze import setup, Executable setup( name = "hello", version = "0.1", description = "Sample cx_Freeze script", executables = [Executable("hello.py")])
打包批處理:command.bat
python setup.py build pause continue