以下是软件链接:https://mysecreat.lanzoub.com/iZPGf0swgtbc
软件功能:可以对py文件进行打包,功能基于pyinstaller模块,因此需要安装python环境,其它不用管,软件会自动检测模块安装情况
分割线-------------------------------------------分割线
以下是源码:
import os, shutil
from configparser import ConfigParser
#配置文件类
class config():
def __init__(self):
self.dist_path=os.getcwd()
self.work_path=self.dist_path+"\\缓存"
self.icon_path=self.dist_path+"\\默认.ico"
self.conf_path=self.dist_path+"\\conf.ini"
self.window_show='no'
self.pyinstaller='no'
self.read_conf()
def config_conf(self):
choice=input("是否使用默认配置?(y/是,n/否)")
if (choice=='y'):
print(f"当前配置如下:\n图标路径:{self.icon_path}\n是否显示窗口:{self.window_show}")
elif(choice=='n'):
self.icon_path=input("请输入图标路径:")
self.window_show=input("是否显示窗口(是:yes 否:no):")
def read_conf(self):
if(os.path.exists(self.conf_path)):
cf=ConfigParser()
cf.read(self.conf_path,encoding='utf-8')
self.work_path=cf['conf']['work_path']
self.dist_path=cf['conf']['dist_path']
self.icon_path=cf['conf']['icon_path']
self.window_show=cf['conf']['window_show']
self.pyinstaller=cf['conf']['pyinstaller']
else:
self.config_conf()
self.save_conf()
def save_conf(self):
cf=ConfigParser()
cf.add_section('conf')
cf.set('conf','work_path',self.work_path)
cf.set('conf','dist_path',self.dist_path)
cf.set('conf','icon_path',self.icon_path)
cf.set('conf','window_show',self.window_show)
cf.set('conf','pyinstaller',self.pyinstaller)
with open(file=self.conf_path,mode="w+",encoding='utf-8') as fp:
cf.write(fp)
#运行主程序
def run():
conf=config()
dist_path=conf.dist_path
work_path=conf.work_path
icon_path=conf.icon_path
window_show=conf.window_show
pyinstaller=conf.pyinstaller
if(pyinstaller=='no'):
install_pyinstaller(conf)
while (True):
wait_path = input("请输入待打包文件路径:")
cache_path_1 = os.getcwd() + r"\build"
cache_path_2 = os.getcwd() + "\\" + os.path.basename(wait_path).rstrip(".py") + ".spec"
if(window_show == 'yes'):
cmd = f"pyinstaller -F -c {wait_path} --distpath {dist_path} -i {icon_path}"
else:
cmd = f"pyinstaller -F -w -c {wait_path} --distpath {dist_path} -i {icon_path}"
try:
print("指令执行成功!")
os.makedirs(work_path, exist_ok=True)
os.system(cmd)
shutil.rmtree(work_path, ignore_errors=True)
shutil.rmtree(cache_path_1, ignore_errors=True)
os.remove(cache_path_2)
except:
print("指令执行失败!")
os.system("pause")
os.system("cls")
#检测是否安装pyinstaller模块
def install_pyinstaller(conf):
cmd="pip install pyinstaller"
os.system(cmd)
os.system("cls")
conf.pyinstaller='yes'
conf.save_conf()
if __name__ == '__main__':
run()