python3以上版本打包exe需要扩展软件:cx_freeze
1)安装后在Python32Scriptscxfreeze.bat和Python32Scriptscxfreeze-quickstart.bat文件中更改python实际路径,如:
C:Python32python.exe C:Python32Scriptscxfreeze %*改为D:Python32python.exe D:Python32Scriptscxfreeze %*
注意:我在64位系统下安装时,出现了小小的问题,命令行提示cxfreeze命令无效、Python32Scripts下没有bat文件,我的解决方案是:
修改cxfreeze、cxfreeze-quickstart文件中python的实际路径,
![](https://images0.cnblogs.com/i/516142/201404/281019456897312.png)
![](https://images0.cnblogs.com/i/516142/201404/281019546737389.png)
然后cmd进入该目录,执行python cxfreeze-postinstall命令,系统会在Python32Scripts目录下生成两个bat文件。
![](https://images0.cnblogs.com/i/516142/201404/281020020332638.png)
![](https://images0.cnblogs.com/i/516142/201404/281020092209899.png)
![](https://images0.cnblogs.com/i/516142/201404/281020148772362.png)
再注意:cxfreeze.bat和cxfreeze-quickstart.bat文件中Python路径若存在空格(如D:Program FilesPython27Python.exe)需要加引号(如"D:Program FilesPython27Python.exe”)否则会报错的!!!
![](https://images0.cnblogs.com/i/516142/201404/281031595022929.png)
![](https://images0.cnblogs.com/i/516142/201404/281032075957334.png)
2)新建py2exe.bat,写入:
@echo off
@cd /d "%~dp0"
d:/python32/scripts/cxfreeze %1 --target-dir=d:py2exe --base-name=win32gui(注:cxfreeze所在路径存在空格需要用引号将路径包含起来)
或cxfreeze %1 --target-dir=d:py2exe --base-name=win32gui(注:如果Python32Scripts目录在系统PATH中)
将需打包的py脚本拖入批处理即可,打包生成文件(exe文件)在target-dir即d:py2exe下