一、软件准备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