py脚本打包exe可执行文件

python3以上版本打包exe需要扩展软件:cx_freeze

1)安装后在\Python32\Scripts\cxfreeze.bat和\Python32\Scripts\cxfreeze-quickstart.bat文件中更改python实际路径,如:
C:\Python32\python.exe C:\Python32\Scripts\cxfreeze %*改为D:\Python32\python.exe D:\Python32\Scripts\cxfreeze %*
注意:我在64位系统下安装时,出现了小小的问题,命令行提示cxfreeze命令无效、\Python32\Scripts\下没有bat文件,我的解决方案是:
修改cxfreeze、cxfreeze-quickstart文件中python的实际路径,
 
 
然后cmd进入该目录,执行python cxfreeze-postinstall命令,系统会在\Python32\Scripts\目录下生成两个bat文件。
再注意:cxfreeze.bat和cxfreeze-quickstart.bat文件中Python路径若存在空格(如D:\Program Files\Python27\Python.exe)需要加引号(如"D:\Program Files\Python27\Python.exe”)否则会报错的!!!
 
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(注:如果\Python32\Scripts\目录在系统PATH中
将需打包的py脚本拖入批处理即可,打包生成文件(exe文件)在target-dir即 d:\py2exe下

转载于:https://www.cnblogs.com/doudongchun/p/3694829.html

猜你喜欢

转载自blog.csdn.net/weixin_33938733/article/details/93959301