Python pyinstaller图形化打包工具
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 subprocess
class 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 = wenjian
wenjian.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 = ico
ico.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 = anniu
anniu.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 = qingchu
qingchu.setText("清空")
qingchu.move(415 , 340-105-40)
self.qingchu.clicked.connect(self.qingchu_cao)
def zhuomian_ui(self):
zhuomian = QCheckBox(self)
self.zhuomian = zhuomian
zhuomian.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 = tishi
tishi.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 = banben
banben.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 = pivi
if 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 = anzhuang
anzhuang.move(300,10)
if self.bbpi == 0:
anzhuang.setText("")
else:
anzhuang.setText("我要安装PyInstaller")
def anzhuang_anniu(self):
azan = QPushButton(self)
self.azan = azan
azan.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 = xianshi
xianshi.setText("使用显式处理")
xianshi.move(20, 265-40)
def tishi2_ui(self):
tishi2 = QLabel(self)
self.tishi2 = tishi2
tishi2.setText("默认使用隐式,显式处理为弹出打包的命令行界面")
tishi2.setStyleSheet('background-color: rgb(255, 251, 100)')
tishi2.move(5, 280-40)
def minglingchuang_ui(self):
minglingchuang = QCheckBox(self)
self.minglingchuang = minglingchuang
minglingchuang.setText("使用命令窗")
minglingchuang.move(20, 255)
def tishi3_ui(self):
tishi3 = QLabel(self)
self.tishi3 = tishi3
tishi3.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 = wenjiananniu
wenjiananniu.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 = icoanniu
icoanniu.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 = sczdwz
sczdwz.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 = sczdwzan
sczdwzan.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 = baocunanniu
baocunanniu.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 = sczdwzts
sczdwzts.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:] + h
shuchu = 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:] + m
shuchu = self.k
os.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.k
os.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 + s
shuchu = 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 + s
shuchu = self.k
os.system(shuchu)
# print(shuchu)
else:
pass
else:
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:] + h
shuchu = 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:] + m
shuchu = 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 + s
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 -i "
j = self.wenjian.toPlainText()
h = self.ico.toPlainText()
m = " --distpath="
s = self.sczdwz.toPlainText()
self.k = i + h[8:] + " " + j[8:] + m + s
shuchu = self.k
# print(shuchu)
subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
else:
pass
else:
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:] + h
shuchu = 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:] + m
shuchu = self.k
os.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.k
os.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 + s
shuchu = 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 + s
shuchu = self.k
os.system(shuchu)
# print(shuchu)
else:
pass
else:
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:] + h
shuchu = 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:] + m
shuchu = 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 + s
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 -i "
j = self.wenjian.toPlainText()
h = self.ico.toPlainText()
m = " --distpath="
s = self.sczdwz.toPlainText()
self.k = i + h[8:] + " " + j[8:] + m + s
shuchu = self.k
# print(shuchu)
subprocess.call(shuchu, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
else:
pass
def 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())
原文地址:https://blog.csdn.net/Clay_K/article/details/144404740
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!