backTop

使用Pyinstaller对Python文件打包

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)

  

posted @ 2019-10-17 10:20  ooops!  阅读(264)  评论(0编辑  收藏  举报