Python pyinstaller图形化打包工具
1.简介:
一个使用Python PYQT5制作的关于pyinstaller打包工具,代替传统的cmd黑窗口模式打包页面,实现更快捷方便的python打包体验。资源已打包,大家可自行下载。
相关功能:
- 识别是否安装了pyinstaller,如果没有的话,打开在左上角会提示,并在右上角增加“安装”按钮。
- 打包过程设置为隐式。并且加入“显示处理”选项。
- 支持一键拖拽文件以及自动选择文件。
- 支持导出到桌面以及设置打包好的软件图标。
pyinstaller 相关参数:
-F 制作独立的可执行程序
-D 制作出的档案存放在同一个文件夹下(默认值)
-K 包含TCL/TK(对于使用了TK的,最好加上这个选项,否则在未安装TK的电脑上无法运行)
-w 制作窗口程序
-c 制作命令行程序(默认)
-X 制作使用UPX压缩过的可执行程序(推荐使用这个选项,需要下载UPX包,解压后upx.exe放在Python(非PyInstaller)安装目录下,下载upx308w.zip)
-o DIR 指定输出SPEC文件路径(这也决定了最后输出的exe文件路径)
–icon=[ICO文件路径] 指定程序图标
-v [指定文件] 指定程序版本信息
-n [指定程序名] 指定程序名称
–distpath=D:/dist 输出到指定位置
2.运行效果:
3.相关源码:
from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QTextEdit, QCheckBox, QLabel, QFileDialog
from PyQt5.QtGui import QIcon
import sys
import os
import subprocessclass WinDow(QWidget):def __init__(self):super().__init__()self.setWindowTitle("Pyinstaller图形化打包工具")self.setMinimumSize(500 , 300)self.setMaximumSize(500 , 300)self.setWindowIcon(QIcon("pussy.ico"))self.wenjian_ui()self.ico_ui()self.anniu_ui()self.qingchu_ui()self.zhuomian_ui()self.tishi_ui()self.banben_ui()self.anzhuang_ui()self.anzhuang_anniu()self.xianshi_anniu()self.tishi2_ui()self.minglingchuang_ui()self.tishi3_ui()self.wenjian_anniu()self.ico_anniu()self.sczdwz_ui()self.sczdwz_xx()self.baocun_anniu()self.sczdwz_tishi()def wenjian_ui(self):wenjian = QTextEdit(self)self.wenjian = wenjianwenjian.resize(480-50-20 , 150-50-50)wenjian.move(10,30)wenjian.setPlaceholderText("可拖拽py文件至此:")wenjian.setTabChangesFocus(True)def ico_ui(self):ico = QTextEdit(self)self.ico = icoico.resize(480-50-20 , 50)ico.move(10,190-50-50)ico.setPlaceholderText("可拖拽ico文件至此:")ico.setTabChangesFocus(True)def anniu_ui(self):anniu = QPushButton(self)self.anniu = anniuanniu.setText("打包生成EXE")anniu.move(415 , 340-105)anniu.resize(80,60)self.anniu.clicked.connect(self.anniu_cao)def qingchu_ui(self):qingchu = QPushButton(self)self.qingchu = qingchuqingchu.setText("清空")qingchu.move(415 , 340-105-40)self.qingchu.clicked.connect(self.qingchu_cao)def zhuomian_ui(self):zhuomian = QCheckBox(self)self.zhuomian = zhuomianzhuomian.setText("输出到桌面")zhuomian.move(20, 345-110-40)# zhuomian.toggled.connect(lambda isChecked :print(isChecked))def guanbibaocun():if self.zhuomian.isChecked() == True:self.sczdwzan.setChecked(False)self.sczdwz.setText("")self.baocunanniu.close()elif self.zhuomian.isChecked() == False and self.baocunanniu.isChecked() ==True:self.baocunanniu.show()zhuomian.clicked.connect(guanbibaocun)def tishi_ui(self):tishi = QLabel(self)self.tishi = tishitishi.setText("支持XP,Win7,Win10等打包到桌面")tishi.setStyleSheet('background-color: rgb(255, 251, 100)')tishi.move(5, 365-113-40)def banben_ui(self):banben = QLabel(self)self.banben = banbenbanben.move(10, 10)cmd = 'pyinstaller -v'pivi = subprocess.call(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)# print(pivi)self.bbpi = piviif self.bbpi == 0:banben.setText("您已安装PyInstaller")else:banben.setText("您目前还没安装PyInstaller")banben.setStyleSheet('color:rgb(255, 10, 10)')def anzhuang_ui(self):anzhuang = QLabel(self)self.anzhuang = anzhuanganzhuang.move(300,10)if self.bbpi == 0:anzhuang.setText("")else:anzhuang.setText("我要安装PyInstaller")def anzhuang_anniu(self):azan = QPushButton(self)self.azan = azanazan.move(415,3)if self.bbpi == 0:azan.close()else:azan.setText("我要安装")azan.clicked.connect(self.anzhuang_cao)def anzhuang_cao(self):a = "pip install pyinstaller"os.system(a)def xianshi_anniu(self):xianshi = QCheckBox(self)self.xianshi = xianshixianshi.setText("使用显式处理")xianshi.move(20, 265-40)def tishi2_ui(self):tishi2 = QLabel(self)self.tishi2 = tishi2tishi2.setText("默认使用隐式,显式处理为弹出打包的命令行界面")tishi2.setStyleSheet('background-color: rgb(255, 251, 100)')tishi2.move(5, 280-40)def minglingchuang_ui(self):minglingchuang = QCheckBox(self)self.minglingchuang = minglingchuangminglingchuang.setText("使用命令窗")minglingchuang.move(20, 255)def tishi3_ui(self):tishi3 = QLabel(self)self.tishi3 = tishi3tishi3.setText("注意:命令行程序请勾选此选项,否则运行时会提示以下报错\n failed to execute scipt XXX")tishi3.setStyleSheet('background-color: rgb(255, 251, 100)')tishi3.move(5, 280-10)def wenjian_anniu(self):wenjiananniu = QPushButton(self)self.wenjiananniu = wenjiananniuwenjiananniu.setText("选择py文件")wenjiananniu.move(430-10, 30+10)# wenjiananniu.resize(30,30)wenjiananniu.adjustSize()wenjiananniu.clicked.connect(self.dakaiwenjian_cao)def dakaiwenjian_cao(self):# dakaiwenjian = QFileDialog.getOpenFileUrl(self)dakaiwenjian = QFileDialog.getOpenFileName(self, "请选择一个PY文件", "./", "python文件(*.py)", "python文件(*.py)")# print(dakaiwenjian)self.wenjian.setText("file:///"+str(dakaiwenjian[0]))def ico_anniu(self):icoanniu = QPushButton(self)self.icoanniu = icoanniuicoanniu.setText("选择ico文件")icoanniu.move(430 - 10, 30 + 10+50+10)# wenjiananniu.resize(30,30)icoanniu.adjustSize()icoanniu.clicked.connect(self.dakaiico_cao)def dakaiico_cao(self):# dakaiwenjian = QFileDialog.getOpenFileUrl(self)dakaiico = QFileDialog.getOpenFileName(self, "请选择一个ico文件", "./", "ico文件(*.ico)", "ico文件(*.ico)")# print(dakaiico)self.ico.setText("file:///"+str(dakaiico[0]))def sczdwz_ui(self):sczdwz = QTextEdit(self)self.sczdwz = sczdwzsczdwz.setText("")sczdwz.move(10 , 170)sczdwz.resize(480-50-20 , 150-50-50-25)sczdwz.setReadOnly(True)def sczdwz_xx(self):sczdwzan = QCheckBox(self)self.sczdwzan = sczdwzansczdwzan.setText("打包文件输出到指定位置")sczdwzan.move(20, 345-110-60-25-10)def guanbizhuomian():if sczdwzan.isChecked() == True:self.zhuomian.setChecked(False)self.baocunanniu.show()else:self.baocunanniu.close()self.sczdwz.setText("")sczdwzan.clicked.connect(guanbizhuomian)def baocun_anniu(self):baocunanniu = QPushButton(self)self.baocunanniu = baocunanniubaocunanniu.setText("选择保存路径")baocunanniu.move(480-50-10 , 345-110-60-5)# wenjiananniu.resize(30,30)baocunanniu.adjustSize()baocunanniu.clicked.connect(self.baocunlujin_cao)baocunanniu.close()def sczdwz_tishi(self):sczdwzts = QLabel(self)self.sczdwzts = sczdwztssczdwzts.setText("打钩后才会显示选择按钮")sczdwzts.move(5, 345-110-60-20)sczdwzts.setStyleSheet('background-color: rgb(255, 251, 100)')def baocunlujin_cao(self):baocunlujin = QFileDialog.getExistingDirectory(self)# print(baocunlujin)self.sczdwz.setText(baocunlujin)def anniu_cao(self):if self.minglingchuang.isChecked() == True:if self.xianshi.isChecked() == True:if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F "j = self.wenjian.toPlainText()h = " --distpath=%UserProfile%/Desktop/dist"self.k = i + j[8:] + hshuchu = self.k# print(shuchu)os.system(shuchu)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "":i = "pyinstaller -F "j = self.wenjian.toPlainText()self.k = i + j[8:]shuchu = self.k# print(shuchu)os.system(shuchu)elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath=%UserProfile%/Desktop/dist"self.k = i + h[8:] + " " + j[8:] + mshuchu = self.kos.system(shuchu)# print(shuchu)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "":i = "pyinstaller -F -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()self.k = i + h[8:] + " " + j[8:]shuchu = self.kos.system(shuchu)# print(shuchu)#这是一段elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F "j = self.wenjian.toPlainText()h = " --distpath="s = self.sczdwz.toPlainText()self.k = i + j[8:] + h + sshuchu = self.k# print(shuchu)os.system(shuchu)elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath="s = self.sczdwz.toPlainText()self.k = i + h[8:] + " " + j[8:] + m + sshuchu = self.kos.system(shuchu)# print(shuchu)else:passelse:if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F "j = self.wenjian.toPlainText()h = " --distpath=%UserProfile%/Desktop/dist"self.k = i + j[8:] + hshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "":i = "pyinstaller -F "j = self.wenjian.toPlainText()self.k = i + j[8:]shuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath=%UserProfile%/Desktop/dist"self.k = i + h[8:] + " " + j[8:] + mshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "":i = "pyinstaller -F -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()self.k = i + h[8:] + " " + j[8:]shuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)#这是第二段elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F "j = self.wenjian.toPlainText()h = " --distpath="s = self.sczdwz.toPlainText()self.k = i + j[8:] + h + sshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath="s = self.sczdwz.toPlainText()self.k = i + h[8:] + " " + j[8:] + m + sshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)else:passelse:if self.xianshi.isChecked() == True:if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F -w "j = self.wenjian.toPlainText()h = " --distpath=%UserProfile%/Desktop/dist"self.k = i + j[8:] + hshuchu = self.k# print(shuchu)os.system(shuchu)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "":i = "pyinstaller -F -w "j = self.wenjian.toPlainText()self.k = i + j[8:]shuchu = self.k# print(shuchu)os.system(shuchu)elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -w -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath=%UserProfile%/Desktop/dist"self.k = i + h[8:] + " " + j[8:] + mshuchu = self.kos.system(shuchu)# print(shuchu)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "":i = "pyinstaller -F -w -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()self.k = i + h[8:] + " " + j[8:]shuchu = self.kos.system(shuchu)# print(shuchu)elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F -w "j = self.wenjian.toPlainText()h = " --distpath="s = self.sczdwz.toPlainText()self.k = i + j[8:] + h + sshuchu = self.k# print(shuchu)os.system(shuchu)elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -w -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath="s = self.sczdwz.toPlainText()self.k = i + h[8:] + " " + j[8:] + m + sshuchu = self.kos.system(shuchu)# print(shuchu)else:passelse:if self.zhuomian.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F -w "j = self.wenjian.toPlainText()h = " --distpath=%UserProfile%/Desktop/dist"self.k = i + j[8:] + hshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() == "":i = "pyinstaller -F -w "j = self.wenjian.toPlainText()self.k = i + j[8:]shuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.zhuomian.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -w -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath=%UserProfile%/Desktop/dist"self.k = i + h[8:] + " " + j[8:] + mshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.zhuomian.isChecked() == False and self.sczdwzan.isChecked() == False and self.ico.toPlainText() != "":i = "pyinstaller -F -w -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()self.k = i + h[8:] + " " + j[8:]shuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() == "":i = "pyinstaller -F -w "j = self.wenjian.toPlainText()h = " --distpath="s = self.sczdwz.toPlainText()self.k = i + j[8:] + h + sshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)elif self.sczdwzan.isChecked() == True and self.ico.toPlainText() != "":i = "pyinstaller -F -w -i "j = self.wenjian.toPlainText()h = self.ico.toPlainText()m = " --distpath="s = self.sczdwz.toPlainText()self.k = i + h[8:] + " " + j[8:] + m + sshuchu = self.k# print(shuchu)subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,stderr=subprocess.PIPE)else:passdef qingchu_cao(self):self.wenjian.clear()self.ico.clear()self.sczdwz.clear()if __name__ == "__main__":app = QApplication(sys.argv)window = WinDow()window.show()sys.exit(app.exec())