Python脚本打包成exe文件

xingyun86 2018-7-17 1913

Python脚本打包成exe文件

py2exe-0.6.9.win32-py2.7.exe 下载

hello.py #python脚本文件

mysetup.py #打包配置文件

运行打包成exe文件命令

然后在当前目录下有个dist目录: 里面有一个 hello.exe 的文件

*注:
*** binary dependencies ***
Your executable(s) also depend on these dlls which are not includ
you may or may not need to distribute them.

Make sure you have the license if you distribute any of them, and
make sure you don’t distribute files belonging to the operating s

WSOCK32.dll – C:\Windows\system32\WSOCK32.dll
USER32.dll – C:\Windows\system32\USER32.dll
ADVAPI32.dll – C:\Windows\system32\ADVAPI32.dll
SHELL32.dll – C:\Windows\system32\SHELL32.dll
KERNEL32.dll – C:\Windows\system32\KERNEL32.dll

生成exe文件的时候,提示这些dll库文件可以加到dll_excludes里面

注解:

includes #是需要包含的文件

dll_excludes #是需要排除的dll文件

compressed #值为1,表示压缩文件

optimize #为优化级别,默认为0。

bundle_files #是指将程序打包成单文件(此时除了exe文件外,还会生成一个zip文件。如果不需要zip文件,还需要设置zipfile = None)
值为1表示pyd和dll文件会被打包到单文件中,且不能从文件系统中加载python模块;
值为2表示pyd和dll文件会被打包到单文件中,但是可以从文件系统中加载python模块(64位的Py2exe不要添加本句)

在脚本里面加载了psutil模块的,运行生成后exe文件报以下错误:

解决:


×
打赏作者
最新回复 (0)
只看楼主
全部楼主
返回