1、安装命令行打包程序:
pip install pyinstaller
2、cmd到程序所在路径,执行打包命令:
pyinstaller check.py --workpath D:\tools\check\tmp --distpath D:\tools\check\desc
–workpath 指定制作过程中临时文件的存放目录
–distpath 指定最终的可执行文件目录所在的父目录
3、运行时双击D:\tools\check\desc\check下check.exe:
想把工具分享给别人,将目录 D:\tools\check\desc下的check文件夹打包即可。
4、如果觉得.exe文件不好找,可以新建runtimehook.py文件,将其他库文件放到单独文件夹下:
runtimehook.py代码如下:
import sys
import os
currentdir = os.path.dirname(sys.argv[0])
libdir = os.path.join(currentdir, "lib")
print(currentdir)
sys.path.append(libdir)
os.environ['path'] += ';./lib'
cmd下执行如下命令:
pyinstaller check.py --workpath D:\tools\check\tmp --distpath D:\tools\check\desc --runtime-hook="runtimehook.py"
命令执行完,新建一个lib文件夹,将除以下4个文件以外的文件,全部放到lib下。