先使用pip下载cx_freeze: pip install cx_freeze
完成安装后,在需要打包的py文件下新建一个setup.py
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
import sys
import os.path
os.environ['TCL_LIBRARY'] = r'C:\Users\lzh\Anaconda3\tcl\tcl8.6'
os.environ['TK_LIBRARY'] = r'C:\Users\lzh\Anaconda3\tcl\tk8.6'
base = []
build_exe_options = dict(packages=['numpy', 'scipy', 'tensorflow'],
includes=['tensorflow'],
include_files=[r"C:\Users\lzh\Anaconda3\DLLs\tcl86t.dll",
r"C:\Users\lzh\Anaconda3\DLLs\tk86t.dll"])
executables = [
Executable('E:/task/FaceRecognition/facenet-master/src/compare.py', base=base, targetName='facenet_test.exe')
]
setup(name='facenet_test',
version='1.0',
description='fece recognition',
options=dict(build_exe=build_exe_options),
executables=executables)
代码中的绝对路径请按照自己主机的位置进行更改
base为空则默认生成的是命令行exe
使用命令行调转到setup.py目录下
在命令行输入python setup.py build进行打包
等待一段时间后,会生成一个build的文件夹,里面就是打包成的exe和调用的动态库。
但是如果直接运行的话会出现错误:
出现问题的原因是它打包进来的对应文件是大写的,程序找不到
文件在build\exe.win-amd64-3.6\lib\scipy\spatial目录下
把对应文件cKDTree改成小写的ckdtree后就可以运行了