1.安装Pyinstaller
pip install pyinstaller
2.对Python文件打包
pyinstaller.exe -F xxx.py #-F Create a one-file bundled executable
3.将文件一起打包到Python程序中
Python中使用
import os
def resource_path(relative_path):
if getattr(sys, 'frozen', False): #是否Bundle Resource
base_path = sys._MEIPASS
else:
base_path = os.path.abspath(".") # 當前文件夾
return os.path.join(base_path, relative_path)
LRSetting=resource_path("LRSetting.bat")
xxx.spec 中修改
binaries=[("LRSetting.bat",".")],
打包命令
pyinstaller -F xxx.spec
使用 uncompyle6 反编译
import uncompyle6 with open("xxx.py","w",encoding='utf8') as f: uncompyle6.decompile_file("xxx.pyc", f)