吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 799|回复: 13
收起左侧

[经验求助] Python 编译的exe文件无法打开,win11、win7

  [复制链接]
xptk9074 发表于 2024-9-14 15:02
80吾爱币
本帖最后由 xptk9074 于 2024-9-18 16:32 编辑

本地用调试正常,可以用,但是编译后就无法打开
以下是代码,求指点哪里错了。
pyinstaller --onefile --hidden-import=PyQt5.QtCore --hidden-import=PyQt5.QtWidgets --hidden-import=PyQt5.QtGui --hidden-import=sqlite3 目的样.py
pyinstaller --onefile 目的样.py  
配置 Visual Studio Code 的任务(tasks.json
[JavaScript] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Compile to exe",
            "type": "shell",
            "command": "pyinstaller --onefile your_script.py",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

编译成功后都打不开


[Python] 纯文本查看 复制代码
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
016
017
018
019
020
021
022
023
024
025
026
027
028
029
030
031
032
033
034
035
036
037
038
039
040
041
042
043
044
045
046
047
048
049
050
051
052
053
054
055
056
057
058
059
060
061
062
063
064
065
066
067
068
069
070
071
072
073
074
075
076
077
078
079
080
081
082
083
084
085
086
087
088
089
090
091
092
093
094
095
096
097
098
099
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
import sqlite3
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QTableWidget, QTableWidgetItem, QPushButton, QHBoxLayout, QLabel, QLineEdit, QComboBox, QScrollArea, QMessageBox
from PyQt5.QtCore import Qt
 
 
page_size =28
current_page = 0
 
 
def query_data(page):
    try:
        conn = sqlite3.connect('C:/Users/TPM/Desktop/VCMDataII.db')
        cursor = conn.cursor()
        offset = page * page_size
        selected_option1 = option_combo1.currentText()
        selected_option2 = option_combo2.currentText()
        query = f"SELECT * FROM T_LV2 WHERE Attribute3 LIKE '%{selected_option2}%' AND BatchId LIKE '%{selected_option1}%' LIMIT {page_size} OFFSET {offset};"
        print(f"Executing query: {query}")
        cursor.execute(query)
        results = cursor.fetchall()
        conn.close()
 
        table.clearContents()
        table.setRowCount (0)
 
        if len(results) > 0:
            for row_num, row_data in enumerate(results):
                table.insertRow(row_num)
                for col_num, data in enumerate(row_data):
                    item = QTableWidgetItem(str(data))
                    item.setTextAlignment(Qt.AlignCenter)
                    table.setItem(row_num, col_num, item)
            # 计算并显示数量统计
            total_count = len(results) / 28
            count_label.setText(f"统计托数:{total_count}")
        else:
            QMessageBox.information(widget, "提示", "未查到相关数据。")
            count_label.setText("统计托数:0")
    except sqlite3.DatabaseError as e:
        QMessageBox.information(widget, "提示", "查询为空或数据库错误。")
        table.clearContents()
        table.setRowCount(0)
        count_label.setText("统计托数:0")
 
 
def next_page():
    global current_page
    current_page += 1
    query_data(current_page)
 
 
def prev_page():
    global current_page
    if current_page > 0:
        current_page -= 1
        query_data(current_page)
 
 
app = QApplication([])
widget = QWidget()
widget.setWindowTitle("目的样查询工具")
widget.resize(600, 400)
 
layout = QVBoxLayout()
 
# 创建第一个下拉框(从 T_BatchInfo 表中 BatchId 获取数据)
try:
    conn = sqlite3.connect('C:/Users/TPM/Desktop/VCMDataII.db')
    cursor = conn.cursor()
    cursor.execute("SELECT DISTINCT BatchId FROM T_BatchInfo")
    batch_ids = [row[0] for row in cursor.fetchall()]
    conn.close()
except sqlite3.DatabaseError as e:
    batch_ids = []
 
option_label1 = QLabel("")
option_combo1 = QComboBox()
option_combo1.addItems(batch_ids)
option_hbox1 = QHBoxLayout()
option_hbox1.addWidget(option_label1)
option_hbox1.addWidget(option_combo1)
layout.addLayout(option_hbox1)
 
# 创建第二个下拉框(原目的样分类下拉框)
option_label2 = QLabel("选择目的样分类:")
option_combo2 = QComboBox()
option_combo2.addItems(['包', 'P ', '接', '开', '停'])
option_hbox2 = QHBoxLayout()
option_hbox2.addWidget(option_label2)
option_hbox2.addWidget(option_combo2)
layout.addLayout(option_hbox2)
 
# 创建查询按钮
query_button = QPushButton("查询")
query_button.clicked.connect(lambda: query_data(current_page))
layout.addWidget(query_button)
 
# 创建滚动区域
scroll_area = QScrollArea()
scroll_area.setWidgetResizable(True)
table_widget = QWidget()
table_layout = QVBoxLayout(table_widget)
table = QTableWidget()
table.setColumnCount(13)
columns = ('箱', '托', '单', '号', '码', '传', 日期', '', '上传', '虚码', '参数一', '参数二', '目的样类别')
table.setHorizontalHeaderLabels(columns)
for col in range(13):
    table.horizontalHeaderItem(col).setTextAlignment(Qt.AlignCenter)
    table.setColumnWidth(col, 80)
table_layout.addWidget(table)
scroll_area.setWidget(table_widget)
layout.addWidget(scroll_area)
 
# 创建数量统计标签
count_label = QLabel("统计托数:0")
layout.addWidget(count_label)
 
# 创建下一页和上一页按钮
next_page_button = QPushButton("下一页")
next_page_button.clicked.connect(next_page)
prev_page_button = QPushButton("上一页")
prev_page_button.clicked.connect(prev_page)
page_hbox = QHBoxLayout()
page_hbox.addWidget(prev_page_button)
page_hbox.addWidget(next_page_button)
layout.addLayout(page_hbox)
 
widget.setLayout(layout)
widget.show()
 
app.exec_()
 
import time








发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| xptk9074 发表于 2024-9-19 08:48
求大神帮忙~
kejqz 发表于 2024-9-19 11:28
exe打不开是什么表现,点开马上闪退还是,一般是引用库文件没成功导入,可以尝试把引用库地址写进打包代码。具体缺了什么库,可以在源代码里面加input函数作为断点看看报错提示消息
heham 发表于 2024-9-19 11:45
pyqt感觉有点玄学,我是一次没成功过,有人说用pyqt自己的那个发布发布编译可以,但是我也没成功
xyj152 发表于 2024-9-19 12:01
你用 CMD 命令窗口打开看看提示什么报错作息,一般是缺少库引起的
 楼主| xptk9074 发表于 2024-9-19 12:37
kejqz 发表于 2024-9-19 11:28
exe打不开是什么表现,点开马上闪退还是,一般是引用库文件没成功导入,可以尝试把引用库地址写进打包代码 ...

无任何反应,任务管理器里也没有
 楼主| xptk9074 发表于 2024-9-19 12:38
xyj152 发表于 2024-9-19 12:01
你用 CMD 命令窗口打开看看提示什么报错作息,一般是缺少库引起的

CMD 运行也是,无任何反应,任务管理器里也没有
 楼主| xptk9074 发表于 2024-9-19 12:39
heham 发表于 2024-9-19 11:45
pyqt感觉有点玄学,我是一次没成功过,有人说用pyqt自己的那个发布发布编译可以,但是我也没成功

是pyqt原因么?我一直怀疑是sqlite3的原因,我把它两都打包生成,还是不行
heham 发表于 2024-9-19 19:21
xptk9074 发表于 2024-9-19 12:39
是pyqt原因么?我一直怀疑是sqlite3的原因,我把它两都打包生成,还是不行

不清楚,我是仅仅pyqt都不成功
Destinyharmony 发表于 2024-9-19 21:39
xptk9074 发表于 2024-9-19 12:39
是pyqt原因么?我一直怀疑是sqlite3的原因,我把它两都打包生成,还是不行

都打包之后,路径改为相对路径了吗?我也觉得是数据库的问题。你运行之后看看任务管理器的进程有吗?
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-22 15:08

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表