一、编写python程序:test.py(待打包的脚本程序)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
if __name__ == "__main__":
print "yes"
二、编写可执行函数的python脚本:
# generate_binary.py
(需要安装cx_Freeze依赖)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
import os
import sys
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need fine tuning.
buildOptions = dict(includes=[], excludes=['collections.sys', 'collections._weakref'])
base = 'Console'
targetName = 'server-test'
# Executable中需要制定需要被打包的脚本文件所在位置
executables = [
Executable('./test.py', base=base, targetName=targetName)
]
setup(name='webservice',
version='0.1.0',
description='server-test-binary',
options=dict(build_exe=buildOptions),
executables=executables)
三、运行步骤2的脚本程序:
python generate_binary.py build --build-exe=create-binary
运行后会生成一个.exe文件,该文件即可直接作为可执行程序执行。