主要有三种方式进行打包py2exe,PyInstaller和cx_Freeze,
py2exe和PyInstaller会出现dll打包不完整和没有最新对应的
python 版本,所以使用cx_freeze1.安装cx_freeze
pip install cx_Freeze==6.01b1
使用cxfreeze --version检验是否安装成功
2.建立setup.py脚本
from cx_Freeze import setup, Executable
# Dependencies are automatically detected, but it might need
# fine tuning.
buildOptions = dict(packages = [], excludes = [])
import sys
import os
os.environ['TCL_LIBRARY'] = 'I:\\Python36\\tcl\\tcl8.6'
os.environ['Tk_LIBRARY'] = 'I:\\Python36\\tcl\\tk8.6'
base = 'Win32GUI' if sys.platform=='win32' else None
includes = []
includes_files = ['I:\\Python36\\DLLs\\tcl86t.dll',
'I:\\Python36\\DLLs\\tk86t.dll']#改成自己存放路径
executables = [
Executable('I:\\Python36\\Scripts\\gui_local_baidu.py', base=base, targetName = 'convert_success.exe')
]#gui_local_baidu.py需要改成自己的py文件
setup(name = 'convert_local',
version = '0.1',
description = 'convert_baidu',
#options = {"build_exe":{"includes":includes,"includes_files":includes_files}},
executables = executables
)
将这个setup.py文件放在与cxfreeze相同的路径之下
3.将这个文件打包成可安装程序
python setup.py bdist_msi
打包之后,便可在当前目录下找到dist文件加中找到msi文件,便可轻松移植啦