[英]pyinstaller creating a useless executable
I got the task to parse a XML script to get certain values into an excel sheet. 我得到了解析XML脚本以将某些值转换为Excel工作表的任务。 The script is running fine, but now I have to create an executable.
该脚本运行良好,但是现在我必须创建一个可执行文件。
After I read several things about it, I thought pyinstaller might be the best way to reach my goal. 在阅读了几本书之后,我认为pyinstaller可能是实现目标的最佳方法。 But it only produces a useless ececutable that does nothing.
但这只会产生无用的可执行文件,什么也不做。
So I read more and found out, that python uses hidden libaries. 因此,我阅读了更多的内容,发现python使用隐藏的库。 I tried to find out, what exactly my hidden libaries are and how to include them, but I failed doing so.
我试图找出隐藏的库到底是什么以及如何包含它们,但是我没有这样做。
I was told to use the "-v" option to get the hidden libaries. 有人告诉我使用“ -v”选项来获取隐藏的库。 But I honestly don't even know, what I'm looking at.
但老实说,我什至不知道我在看什么。
If I tried writing something into the "hiddenimports" in the spec-file, but it got overwritten. 如果我尝试将某些内容写入规格文件中的“ hiddenimports”,但该内容将被覆盖。 So I'm not completely sure if it got used or not.
因此,我不确定它是否被使用过。
I attached the code, it should all be standard libary. 我附上了代码,所有代码都应该是标准库。
Could someone please point me to what I'm missing? 有人可以指出我所缺少的吗?
Thank you! 谢谢!
from xml.etree import ElementTree import openpyxl import tkinter as tk from tkinter import filedialog import time def getFileName(filepath): print("File Path: {}".format(filepath)) split1 = filepath.split(".") split2 = split1[0].split("/") print("Filename: {}".format(split2[-1])) return split2[-1] def parseFile(input_file): xmlTree = ElementTree.parse(input_file) xmlRoot = xmlTree.getroot() filename = getFileName(input_file) comm = xmlRoot.find('vehicle/communications') ECUS_events = comm.find("ecus[@type='read_events']") ECUS_diag = comm.find("ecus[@type='single_ecu_diagnostic']") ECUS_meas = comm.find("ecus[@type='read_measurements']") print("ECUS: 'Read_Events':{}, 'Read_Measurements':{}, 'Single_Diagnostic':{}".format((ECUS_events is not None), (ECUS_meas is not None), (ECUS_diag is not None))) print("ECUS: {}, {}, {}\\n".format(ECUS_events, ECUS_meas, ECUS_diag)) ecus = [] dtc = [] for ECU in ECUS_events.iter('ecu'): ecu = [] ecu_name = ECU.find('ecu_name').text ecu_id = ECU.find('ecu_id').text print("ECU: {} - {}".format(ecu_id, ecu_name)) ecu.append(ecu_name) ecu.append(ecu_id) ecu_master_ident = ECU.find("ecu_master[@type='ident']") if ecu_master_ident is not None: for value in ecu_master_ident.iter('values'): if value.find('display_name') is not None: if value.find('display_name').text == "SoftwareVersion": SW_version = value.find('display_value').text print("Found SW ver: {}".format(SW_version)) ecu.append(SW_version) if value.find('display_name') is not None: if value.find('display_name').text == "HardwareVersion": HW_version = value.find('display_value').text print("Found HW ver: {}".format(HW_version)) ecu.append(HW_version) if value.find('display_name') is not None: if value.find('display_name').text == "VW/Audi part number": VW_AUDI_part = value.find('display_value').text print("Found VW/Audi #: {}".format(VW_AUDI_part)) ecu.append(VW_AUDI_part) if value.find('display_name') is not None: if value.find('display_name').text == "Hardware part number": HW_part = value.find('display_value').text print("Found HW #: {}".format(HW_part)) ecu.append(HW_part) ecu_master_dtc = ECU.find("ecu_master[@type='event_memory']") DTC_count = 0 if ecu_master_dtc is not None: DTCs = ecu_master_dtc.findall('values') for DTC in DTCs: DTC_count += 1 DTC_name = DTC.find('display_name') DTC_number = DTC.find('fault_number') DTC_text = DTC.find('dtc_text') DTC_ecu = ecu_id + " - " + ecu_name print("DTC: {} - {} | {}".format(DTC_number.text, DTC_name.text, DTC_text.text)) dtc.append([DTC_number.text, DTC_name.text, DTC_text.text, DTC_ecu]) if DTC_count: print("DTC Count: {}".format(DTC_count)) else: print("No DTC Category") ecu.append(DTC_count) print("\\n") ecus.append(ecu) single_diag = [] if ECUS_diag is not None: for ECU in ECUS_diag.iter('ecu'): ecu_info = [] ecu_name = ECU.find('ecu_name').text ecu_id = ECU.find('ecu_id').text length = len(ecu_name) + len(ecu_id) + 18 for char in range(0, length): print("-", end="") print("\\n---- ECU: {} - {} ----".format(ecu_id, ecu_name)) for char in range(0, length): print("-", end="") print("") ecu_info.append(ecu_name) ecu_info.append(ecu_id) ecu_master_ident = ECU.find("ecu_master[@type='ident']") if ecu_master_ident is not None: for value in ecu_master_ident.iter('values'): if value.find('display_name') is not None: if value.find('display_name').text == "Coding": coding = value.find('display_value').text print("Found Coding: {}".format(coding)) ecu_info.append(coding) ecu_master_adapt = ECU.find("ecu_master[@type='adaption_read']") ecu_adaption = [] if ecu_master_adapt is not None: print("Gathering 'Adaption' data...") for values in ecu_master_adapt.findall('values'): adapt_list = [] Outer_cat = values.find('display_name') adapt_list.append(Outer_cat.text) value_list = [] for value in values.findall('values'): inner_name = value.find('display_name') inner_val = value.find('display_value') if inner_name is not None and inner_val is not None: value_list.append([inner_name.text, inner_val.text]) elif inner_val is not None: value_list.append([inner_val.text]) elif inner_name is not None: value_list.append([inner_name.text]) else: value_list.append([]) adapt_list.append(value_list) ecu_adaption.append(adapt_list) ecu_master_coding = ECU.find("ecu_master[@type='coding_read']") ecu_coding = [] if ecu_master_coding is not None: print("Gathering 'Coding' data...") for values in ecu_master_coding.findall('values'): code_list = [] val_list = [] code_name = values.find('display_name') code_val = values.find('display_value') code_bin = values.find('bin_value') code_hex = values.find('hex_value') if code_name is not None: code_list.append(code_name.text) else: print("No Code Name present") code_list.append("None") if code_val is not None: val_list.append(code_val.text) if code_bin is not None: val_list.append(["Hex", code_bin.text]) if code_bin is not None: val_list.append(["Bin", code_hex.text]) code_list.append(val_list) # print(code_list) ecu_coding.append(code_list) single_diag.append([ecu_info, ecu_adaption, ecu_coding]) meas_ocu = [] if ECUS_meas is not None: for ECU in ECUS_meas.iter('ecu'): ecu_name = ECU.find('ecu_name').text ecu_id = ECU.find('ecu_id').text if ecu_name == "Telematics Communication Unit" and ecu_id == "0075": ocu_info = [ecu_name, ecu_id] length = len(ecu_name) + len(ecu_id) + 18 for char in range(0, length): print("-", end="") print("\\n---- OCU: {} - {} ----".format(ecu_id, ecu_name)) for char in range(0, length): print("-", end="") print("") ocu_master = ECU.find("ecu_master[@type='measurement']") ocu_values = [] for Values in ocu_master.findall('values'): display_name = Values.find('display_name') if display_name is not None: print(display_name.text) values_disp = [] for values in Values.findall('values'): disp_value = values.find('display_value') disp_unit = values.find('display_unit') disp_name = values.find('display_name') if disp_value is not None and disp_unit is not None and disp_name is not None: print("Name: {} | Value: {} {}".format(disp_name.text, disp_value.text, disp_unit.text)) values_disp.append([disp_name.text, "{} {}".format(disp_value.text, disp_unit.text)]) elif disp_value is not None and disp_name is not None: print("Name: {} | Value: {}".format(disp_name.text, disp_value.text)) values_disp.append([disp_name.text, disp_value.text]) elif disp_value is not None and disp_unit is not None: print("Value: {} {}".format(disp_value.text, disp_unit.text)) values_disp.append(["{} {}".format(disp_value.text, disp_unit.text)]) elif disp_value is not None: print("Value: {}".format(disp_value.text)) values_disp.append([disp_value.text]) ocu_values.append([display_name.text, values_disp]) print("") meas_ocu.append([[ecu_name, ecu_id], ocu_values]) print("\\n") print("Printing final structures:\\n") print("ECU Readouts:") for elem in ecus: print(elem) print("\\nDTC Readouts:") for elem in dtc: print(elem) book = openpyxl.Workbook() sheet_ecu = book.active sheet_ecu.title = 'ECUs' sheet_dtc = book.create_sheet("DTCs", 1) sheet_0075 = book.create_sheet("ECU - 0075", 2) sheet_005F = book.create_sheet("ECU - 005F", 3) print("\\nWriting to workbook...") sheet_ecu.cell(row=1, column=1, value="ECU Name") sheet_ecu.cell(row=1, column=2, value="ECU ID") sheet_ecu.cell(row=1, column=3, value="SW") sheet_ecu.cell(row=1, column=4, value="HW") sheet_ecu.cell(row=1, column=5, value="VW/Audi #") sheet_ecu.cell(row=1, column=6, value="HW #") sheet_ecu.cell(row=1, column=7, value="DTCs") sheet_dtc.cell(row=1, column=1, value="DTC #") sheet_dtc.cell(row=1, column=2, value="Name") sheet_dtc.cell(row=1, column=3, value="Text") sheet_dtc.cell(row=1, column=4, value="ECU") sheet_005F.cell(row=1, column=1, value="No '005F' diagnostic found") sheet_0075.cell(row=1, column=1, value="No '0075' diagnostic found") cur_row = 2 for elem in ecus: cur_column = 1 for cell in elem: sheet_ecu.cell(row=cur_row, column=cur_column, value=cell) cur_column += 1 cur_row += 1 cur_row = 2 for elem in dtc: cur_column = 1 for cell in elem: sheet_dtc.cell(row=cur_row, column=cur_column, value=cell) cur_column += 1 cur_row += 1 telecom_cur_row = 0 if len(single_diag) > 0: print("Single Diag: {} {}".format(len(single_diag), [single_diag[0][0][1], single_diag[1][0][1]])) for diag in single_diag: print("ECU Diagnostic:{} - {}".format(diag[0][1], diag[0][0])) if diag[0][1] == "0075": sheet_0075.cell(row=1, column=1, value=diag[0][1]) sheet_0075.cell(row=1, column=2, value=diag[0][0]) sheet_0075.cell(row=2, column=1, value="Coding") sheet_0075.cell(row=2, column=2, value=diag[0][2]) sheet_0075.cell(row=4, column=1, value="--Adaption--") cur_row = 5 for element in diag[1]: sheet_0075.cell(row=cur_row, column=1, value=element[0]) if len(element[1]) > 1: string = "" for value in element[1]: string += "{} : {}".format(value[0], value[1]) + " \\n" else: string = element[1] while type(string) is list: string = string[0] sheet_0075.cell(row=cur_row, column=2, value=string) cur_row += 1 sheet_0075.cell(row=cur_row + 1, column=1, value="--Coding--") cur_row += 2 for element in diag[2]: sheet_0075.cell(row=cur_row, column=1, value=element[0]) if len(element[1]) > 1: string = "" for value in element[1]: string += "{} : {}".format(value[0], value[1]) + " \\n" else: string = element[1] while type(string) is list: string = string[0] sheet_0075.cell(row=cur_row, column=2, value=string) cur_row += 1 telecom_cur_row = cur_row + 1 if diag[0][1] == "005F": sheet_005F.cell(row=1, column=1, value=diag[0][1]) sheet_005F.cell(row=1, column=2, value=diag[0][0]) sheet_005F.cell(row=2, column=1, value="Coding") sheet_005F.cell(row=2, column=2, value=diag[0][2]) sheet_005F.cell(row=4, column=1, value="--Adaption--") cur_row = 5 for element in diag[1]: sheet_005F.cell(row=cur_row, column=1, value=element[0]) if len(element[1]) > 1: string = "" for value in element[1]: string += "{} : {}".format(value[0], value[1]) + " \\n" else: string = element[0] while type(string) is list: string = string[0] sheet_005F.cell(row=cur_row, column=2, value=string) cur_row += 1 sheet_005F.cell(row=cur_row + 1, column=1, value="--Coding--") cur_row += 2 for element in diag[2]: sheet_005F.cell(row=cur_row, column=1, value=element[0]) if len(element[1]) > 1: string = "" for value in element[1]: string += "{} : {}".format(value[0], value[1]) + " \\n" else: string = element[1] while type(string) is list: string = string[0] sheet_005F.cell(row=cur_row, column=2, value=string) cur_row += 1 if len(meas_ocu) > 0: # print(meas_ocu) if telecom_cur_row == 0: telecom_cur_row = 3 for diag in meas_ocu: cur_row = telecom_cur_row print("OCU Diagnostic: {} - {}".format(diag[0][0], diag[0][1])) if diag[0][1] == "0075": sheet_0075.cell(row=cur_row, column=1, value="--Measured Values--") cur_row += 1 for element in diag[1]: sheet_0075.cell(row=cur_row, column=1, value=element[0]) if len(element[1]) > 1: string = "" for value in element[1]: string += "{} : {}".format(value[0], value[1]) + " \\n" elif len(element[1]) == 1: string = element[1] while type(string) is list: string = string[0] sheet_0075.cell(row=cur_row, column=2, value=string) cur_row += 1 print("Saving to '.xlsx' file....") book.save("{}_parsed.xlsx".format(filename)) print("Complete") def verifyFile(filename): approve = 1 print("File Path: {}".format(filename)) split1 = filename.split(".") if split1[1] == "xml": print("File Extension Match!") else: approve = 0 print("File Extension '{}' Incorrect, rejecting".format(split1[1])) print("") return approve def buttonPrompt(): root = tk.Tk() root.withdraw() file_path = filedialog.askopenfilename() print(file_path) if verifyFile(file_path): parseFile(file_path) else: print("File Rejected") if __name__ == '__main__': buttonPrompt()
I had this same problem a while back you have to add a hook to pyinstaller to get it to work. 不久前我遇到了同样的问题,您必须在pyinstaller中添加一个钩子才能使其正常工作。
See: 看到:
# ./buildhoos/hook-openpyxl.py
from PyInstaller.utils.hooks import collect_data_files
datas = collect_data_files('openpyxl')
add it to the Analysis section of the spec like hookspath=['./buildhooks'],
将其添加到规范的“分析”部分,例如
hookspath=['./buildhooks'],
Let me know if I need to clarify anything further! 让我知道是否需要进一步澄清!
Tim 提姆
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.