本节将介绍py2exe 的options参数,用来指定setup的设置选项,options的关键字包括:
unbuffered - if true, use unbuffered binary stdout and stderr <span style="font-family: Arial, Helvetica, sans-serif;"> #1</span> optimize - string or int (0, 1, or 2) includes - list of module names to include packages - list of packages to include with subpackages ignores - list of modules to ignore if they are not found excludes - list of module names to exclude dll_excludes - list of dlls to exclude dist_dir - directory where to build the final files typelibs - list of gen_py generated typelibs to include (XXX more text needed)
这些选项都很简单,这篇涉及dist_dir 这个设置选项参数。
对于dist_dir 的应用很简单,默认情况下,打包生成的文件将放在dist子目录下;如果你不想放在这里也可以设置目标文件的存放目录。
可以使用相对路径(我的电脑上使用绝对路径时报错,找不到目录)来设置。
例如,原文件在source目录下,想把目标目录设置为release(与source在同一层目录),则在setup.py中添加这样一句话:
options = {"py2exe": {<span style="background-color: rgb(255, 255, 153);">"dist_dir":'../release'</span>} } setup( version = "0.5.0", description = "py2exe sample script", name = "py2exe samples", options = options, # targets to build windows = ["Super_Down.py"], )
附图:
其实还有个选项参数没有列出来,就是 compressed ,compressed 值为1,则压缩;为0,不压缩,默认为0。
这个参数指定的是压缩文件(默认为'library.zip')的行为,可以右键查看文件属性中'Archive'的压缩率。
options = {"py2exe": {<span style="background-color: rgb(255, 255, 153);">"compressed": 1</span> } } setup( version = "0.5.0", description = "py2exe sample script", name = "py2exe samples", options = options, # targets to build windows = ["Super_Down.py"], )附图: