基于pyinstaller的python打包工具
以下是软件链接: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()
基于pyinstaller的python打包工具的更多相关文章
- $python打包工具pyinstaller的用法
pyinstaller是一个很好用的python打包工具,在Windows环境下可以将python脚本打包成一个exe可执行文件,并且脚本中所依赖的各种第三方库在打包时候都会被统一处理到一起,这样打包 ...
- Python打包工具setuptools的使用
将我们写的Python程序发布成包后,可以使其能够安装使用. 在项目上测试的时候,某些情况下,可以将Python打包,然后上传到测试服务器,安装测试. setuptools是常用的打包工具. 一个简单 ...
- python打包工具pyinstaller的使用
安装PyInstaller pip install pyinstaller 安装完后,检查安装成功与否: pyinstaller --version 安装成功后,就可以使用下面的命令了: pyinst ...
- python打包工具 --- pyinstaller
安装 安装python并添加到环境变量之后,在终端执行如下命令即可: pip install pyinstaller 截图如下: 若安装失败,可到: https://www.lfd.uci.edu/~ ...
- python打包工具distutils、setuptools分析
在上一篇博文中总结了python中导入包,安装包一条完整的线路.其中有一个有意思的知识点,安装包的方式有很多种,模块和包管理中打包,发布,安装也是值得研究的内容. python中安装包的方式有很多种: ...
- Python打包工具
打包Python应用,使用工具: 1.Linux和Windows下,使用pyinstaller pyinstaller -F -w XXX.py 在当前文件夹下生成两个文件夹:build .dist ...
- 使用pyinstaller将Python打包为exe文件
当我们完成一个Python项目或一个程序时,希望将Python的py文件打包成在Windows系统下直接可以运行的exe程序,那么pyInstaller就是一个很好的选择.pyInstaller可以将 ...
- python打包工具distutils、setuptools的使用
python中安装包的方式有很多种: 源码包:python setup.py install 在线安装:pip install 包名(linux) / easy_install 包名(window) ...
- Pyinstaller(python打包为exe文件)
需求分析: python脚本如果在没有安装python的机器上不能运行,所以将脚本打包成exe文件,降低脚本对环境的依赖性,同时运行更加迅速. 当然打包的脚本似乎不是在所有的win平台下都能使用, ...
- python打包工具 cx_Freeze介绍
原理 Python 脚本在装有 Python 的系统中可以直接双击运行,但绝大多数普通用户并没有配置此类环境,而编译为可执行二进制文件后,用户无需预先安装 Python 及依赖库即可像运行普通程序一样 ...
随机推荐
- MapReduce实践
1. 词频统计任务要求 首先,在Linux系统本地创建两个文件,即文件wordfile1.txt和wordfile2.txt.在实际应用中,这两个文件可能会非常大,会被分布存储到多个节点上.但是,为了 ...
- 字符串练习1 于是他错误的点名开始了(Trie)
题目链接在这里:P2580 于是他错误的点名开始了 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn) 是一道trie树的板子题,注意理解trie树的每一个节点代表的是一个状态,这个状态 ...
- NX二次开发VS环境搭建
1.安装VS2019(直接安装高版本:与NX匹配时向下兼容,不需要纠结) 2.安装习惯使用的NX(建议直接上NX1980,新版不管是功能还是界面都比低版好用得多.很多人说新版不好用,这只是个人习惯和接 ...
- linux使用iperf3测试带宽
1. https://www.alibabacloud.com/help/zh/express-connect/latest/test-the-performance-of-an-express-co ...
- [转]C++回调函数
回调函数 回调函数是一个时时听到的概念,比如在windows API编程时遇到的WinProc函数,就是我们编写而由操作系统调用的函数.现在,我们需要慢慢又详细的记录一下这个问题. 库与使用者的问题 ...
- 30天帮你一步步学会Python的开源项目
最近发现一个不错的免费开源学习项目:30天学会Python 如果您最近有学习Python的打算,不妨看看这个是否适合你? 项目地址:https://github.com/Asabeneh/30-Day ...
- 基于SpringBoot WebMagic爬虫爬取大乐透双色球
大乐透网页地址:https://kjh.55128.cn/dlt-history-360.htm 双色球网页地址:https://kjh.55128.cn/ssq-history-120.htm ...
- 3、IOC创建对象的方法
目录 3.IOC创建对象的方法 4.Spring配置 4.1.别名 4.2.Bean的配置 4.3.import 5.依赖注入 5.1.构造器注入 5.2.Set方式注入[重点] 5.3.扩展方式注入 ...
- 聊天小精灵ChatGPT,好与不好大揭秘!
一.引言 在一个遥远的地球上,有一个名为ChatGPT的魔法盒子,它能够用智慧回答你的问题,解决你的困扰.它是一个聪明的家伙,但和任何家伙一样,有优点也有缺点.现在就让我们一起来探索这个神秘的魔法盒子 ...
- ChatGPT如何助力DevOps|用例解读
DevOps 是一种方法论,旨在提高软件开发和 IT 运营团队的协作和效率.DevOps 涉及各种任务和流程的自动化,例如规划.编码.测试.部署.监控和故障排除.然而,其中一些任务和流程仍然有大量任务 ...