鱼C论坛

 找回密码
 立即注册
查看: 279|回复: 5

打包安装程序的时候,提示BrokenPipeError

[复制链接]
发表于 2024-6-5 14:39:13 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
准备写一个成品输出二维码的代码,信息保存在excel里面,程序在pycharm是可以运行的,但是打包的时候提示 BrokenPipeError,不知道有没有大神解决过没有,本人是一个小白,谢谢!
WX20240605-143708@2x.png
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2024-6-5 14:39:37 | 显示全部楼层
首先,"BrokenPipeError"错误通常发生在程序试图写入一个已关闭的管道时。这可能是因为打包后的程序无法找到必要的资源文件或模块,或者在打包过程中发生了其他错误。

要解决问题,以下是几个可能的解决办法:

1. 确保程序中使用的所有资源文件(如Excel文件)都正确地包含在打包的程序中。您可以使用PyInstaller等工具来打包程序,并确保将所有需要的资源文件一起打包。

2. 确保程序所依赖的第三方模块也被正确地包含在打包的程序中。可以使用PyInstaller的`--hidden-import`参数来指定需要手动导入的模块。

3. 检查程序中是否有网络连接操作或其他需要外部资源的操作。如果有,确保打包的程序能够正常访问这些资源。

4. 尝试在命令行中运行打包后的程序,以查看是否有额外的错误消息或警告。使用命令行可以更好地调试和查找问题。

下面是一个示例代码,用于读取Excel文件并生成二维码。请注意,这只是一个示例,您需要根据实际情况进行相应的修改和适配。
import openpyxl
from qrcode import make as make_qr_code

def generate_qr_codes_from_excel(excel_file):
    workbook = openpyxl.load_workbook(excel_file)
    sheet = workbook.active

    for row in sheet.iter_rows(values_only=True):
        data = row[0]  # 假设数据在第一列
        qr_code = make_qr_code(data)
        qr_code.save(f'{data}.png')

if __name__ == '__main__':
    excel_file = 'data.xlsx'
    generate_qr_codes_from_excel(excel_file)

希望以上解答对您有所帮助!

以上回复来自 FishC AI 小助理,如未能正确解答您的问题,请继续追问。
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

发表于 2024-6-5 16:09:01 | 显示全部楼层


打包时候带上 -debug 看看具体在哪里出现问题

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-6-6 10:43:08 | 显示全部楼层
(base) hanjiandeMacBook-Pro:FP-qrcode hanjian$ pyinstaller -F FP-qrcode.py -debug
usage: pyinstaller [-h] [-v] [-D] [-F] [--specpath DIR] [-n NAME]
                   [--add-data <SRC;DEST or SRC:DEST>]
                   [--add-binary <SRC;DEST or SRC:DEST>] [-p DIR]
                   [--hidden-import MODULENAME]
                   [--collect-submodules MODULENAME]
                   [--collect-data MODULENAME] [--collect-binaries MODULENAME]
                   [--collect-all MODULENAME] [--copy-metadata PACKAGENAME]
                   [--recursive-copy-metadata PACKAGENAME]
                   [--additional-hooks-dir HOOKSPATH]
                   [--runtime-hook RUNTIME_HOOKS] [--exclude-module EXCLUDES]
                   [--splash IMAGE_FILE]
                   [-d {all,imports,bootloader,noarchive}]
                   [--python-option PYTHON_OPTION] [-s] [--noupx]
                   [--upx-exclude FILE] [-c] [-w]
                   [-i <FILE.ico or FILE.exe,ID or FILE.icns or Image or "NONE">]
                   [--disable-windowed-traceback] [--version-file FILE]
                   [-m <FILE or XML>] [--no-embed-manifest] [-r RESOURCE]
                   [--uac-admin] [--uac-uiaccess] [--win-private-assemblies]
                   [--win-no-prefer-redirects] [--argv-emulation]
                   [--osx-bundle-identifier BUNDLE_IDENTIFIER]
                   [--target-architecture ARCH] [--codesign-identity IDENTITY]
                   [--osx-entitlements-file FILENAME] [--runtime-tmpdir PATH]
                   [--bootloader-ignore-signals] [--distpath DIR]
                   [--workpath WORKPATH] [-y] [--upx-dir UPX_DIR] [-a]
                   [--clean] [--log-level LEVEL]
                   scriptname [scriptname ...]
pyinstaller: error: argument -d/--debug: invalid choice: 'ebug' (choose from 'all', 'imports', 'bootloader', 'noarchive')
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-6-6 10:50:04 | 显示全部楼层
代码如下:
import PySimpleGUI as sg
from openpyxl import load_workbook, Workbook
import openpyxl
import qrcode
from PIL import Image
import io
import datetime
import sys
import os
import pandas as pd

def main():
    if __name__ == '__main__':
        main()
sg.theme('DarkTeal4')




###############数据输入界面####################
layout = [
    [sg.Text('请输入产品信息')],
    [sg.Text('批次号'), sg.InputText(key='-批次号-')],
    [sg.Text('供应商名称'), sg.InputText(key='-供应商名称-')],
    [sg.Text('供应商代码'), sg.InputText(key='-供应商代码-')],
    [sg.Text('产品名称'), sg.InputText(key='-产品名称-')],
    [sg.Text('生产日期'), sg.InputText(key='-生产日期-')],
    [sg.Button('确定'), sg.Button('取消')],
]

window = sg.Window('出库产品信息', layout)





while True:
    event, values = window.read()
    if event == sg.WINDOW_CLOSED or event == '取消':
        break
    if event == '确定':
        BASE_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))  # 指定附件excel所在目录路径
        excel_file_path = os.path.join(BASE_DIR, 'product.xlsx')  # 指定excel文件路径
        df = pd.read_excel(excel_file_path)  # 读取excel文件
        print(df.head())  # 显示数据的前几行
        batch_number = values['-批次号-']
        supplier_name = values['-供应商名称-']
        supplier_code = values['-供应商代码-']
        product_name = values['-产品名称-']
        production_date = values['-生产日期-']

        new_row_data = [
            batch_number,
            supplier_name,
            supplier_code,
            product_name,
            production_date
        ]

        try:
            wb = load_workbook(excel_file_path)
            ws = wb.active
        except FileNotFoundError:
            wb = Workbook()
            ws = wb.active

        ws.append(new_row_data)

        try:
            wb.save(excel_file_path)
            sg.popup('数据已追加到Excel文件中。')
        except Exception as e:
            sg.popup(f'保存数据到Excel文件时发生错误:{e},请重试。')
###########读取excel文件#####################

BASE_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))  # 指定附件excel所在目录路径
excel_file_path = os.path.join(BASE_DIR,'product.xlsx') # 指定excel文件路径
df = pd.read_excel(excel_file_path) # 读取excel文件


headers = [cell.value for cell in ws[1]]
combined_data = ','.join(new_row_data)

qr = qrcode.QRCode(
    version=1,
    error_correction=qrcode.constants.ERROR_CORRECT_L,
    box_size=10,
    border=4,
)
qr.add_data(headers)
qr.add_data(combined_data)
qr.make(fit=True)

now = datetime.datetime.now()
date_str = now.strftime("%Y%m%d")
filename = f'出库产品_{date_str}.png'

img = qr.make_image(fill_color="black", back_color="white")
img.save(filename)

byte_arr = io.BytesIO()
img.save(byte_arr, format='PNG')
byte_arr = byte_arr.getvalue()

layout = [[sg.Image(data=byte_arr, key='-QRCODE-')]]
window = sg.Window('QR Code Display', layout, finalize=True)

try:
    while True:
        event, values = window.read()
        if event == sg.WIN_CLOSED or event == 'Exit':
            break
except Exception as e:
    print(f"发生错误:{e}")
finally:
    window.close()
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2024-6-6 11:12:45 | 显示全部楼层
(base) hanjiandeMacBook-Pro:FP-qrcode hanjian$ pyinstaller --debug=all -D FP-qrcode.py
2138 INFO: PyInstaller: 5.13.2
2138 INFO: Python: 3.7.4 (conda)
2163 INFO: Platform: Darwin-22.6.0-x86_64-i386-64bit
2165 INFO: wrote /Users/hanjian/Downloads/Private/Python/pythonProject/pythonProject/FP-qrcode/FP-qrcode.spec
2185 INFO: Extending PYTHONPATH with paths
['/Users/hanjian/Downloads/Private/Python/pythonProject/pythonProject/FP-qrcode']
pygame 2.3.0 (SDL 2.24.2, Python 3.7.4)
Hello from the pygame community. https://www.pygame.org/contribute.html
5881 INFO: checking Analysis
5882 INFO: Building Analysis because Analysis-00.toc is non existent
5883 INFO: Initializing module dependency graph...
5889 INFO: Caching module graph hooks...
5915 INFO: Analyzing base_library.zip ...
11294 INFO: Loading module hook 'hook-encodings.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
13414 INFO: Loading module hook 'hook-heapq.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
13884 INFO: Loading module hook 'hook-pickle.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
16147 INFO: Caching module dependency graph...
16318 INFO: running Analysis Analysis-00.toc
16328 INFO: Analyzing /Users/hanjian/Downloads/Private/Python/pythonProject/pythonProject/FP-qrcode/FP-qrcode.py
16403 INFO: Loading module hook 'hook-openpyxl.py' from '/opt/anaconda3/lib/python3.7/site-packages/_pyinstaller_hooks_contrib/hooks/stdhooks'...
16802 INFO: Loading module hook 'hook-numpy.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
17574 INFO: Loading module hook 'hook-platform.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
17725 INFO: Loading module hook 'hook-xml.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
19838 INFO: Loading module hook 'hook-difflib.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
20380 INFO: Loading module hook 'hook-pandas.py' from '/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks'...
Traceback (most recent call last):
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/isolated/_parent.py", line 372, in call
    return isolated.call(function, *args, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/isolated/_parent.py", line 293, in call
    ok, output = loads(b64decode(self._read_handle.readline()))
EOFError: EOF read where object expected

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/anaconda3/bin/pyinstaller", line 10, in <module>
    sys.exit(_console_script_run())
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/__main__.py", line 194, in _console_script_run
    run()
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/__main__.py", line 180, in run
    run_build(pyi_config, spec_file, **vars(args))
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/__main__.py", line 61, in run_build
    PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 1019, in main
    build(specfile, distpath, workpath, clean_build)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 944, in build
    exec(code, spec_namespace)
  File "/Users/hanjian/Downloads/Private/Python/pythonProject/pythonProject/FP-qrcode/FP-qrcode.spec", line 20, in <module>
    noarchive=True,
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 429, in __init__
    self.__postinit__()
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/building/datastruct.py", line 184, in __postinit__
    self.assemble()
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/building/build_main.py", line 590, in assemble
    priority_scripts.append(self.graph.add_script(script))
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 268, in add_script
    self._top_script_node = super().add_script(pathname)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1359, in add_script
    self._process_imports(n)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2811, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 432, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2264, in _safe_import_hook
    target_attr_names=None, level=level, edge_attr=edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1432, in import_hook
    source_package, target_module_partname, level)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1611, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 479, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1992, in _safe_import_module
    self._process_imports(n)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2811, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 432, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2264, in _safe_import_hook
    target_attr_names=None, level=level, edge_attr=edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1444, in import_hook
    submodule = self._safe_import_module(head, mname, submodule)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 479, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1992, in _safe_import_module
    self._process_imports(n)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2811, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 432, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2264, in _safe_import_hook
    target_attr_names=None, level=level, edge_attr=edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1432, in import_hook
    source_package, target_module_partname, level)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1611, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 479, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1992, in _safe_import_module
    self._process_imports(n)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2811, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 432, in _safe_import_hook
    return super()._safe_import_hook(target_module_partname, source_module, target_attr_names, level, edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2264, in _safe_import_hook
    target_attr_names=None, level=level, edge_attr=edge_attr)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1432, in import_hook
    source_package, target_module_partname, level)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1611, in _find_head_package
    target_module_headname, target_package_name, source_package)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 479, in _safe_import_module
    return super()._safe_import_module(module_basename, module_name, parent_package)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 1992, in _safe_import_module
    self._process_imports(n)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/lib/modulegraph/modulegraph.py", line 2811, in _process_imports
    target_modules = self._safe_import_hook(*import_info, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 368, in _safe_import_hook
    excluded_imports = self._find_all_excluded_imports(source_module.identifier)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/analysis.py", line 356, in _find_all_excluded_imports
    excluded_imports.update(module_hook.excludedimports)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/imphook.py", line 316, in __getattr__
    self._load_hook_module()
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/depend/imphook.py", line 383, in _load_hook_module
    self._hook_module = importlib_load_source(self.hook_module_name, self.hook_filename)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/compat.py", line 613, in importlib_load_source
    return mod_loader.load_module()
  File "<frozen importlib._bootstrap_external>", line 407, in _check_name_wrapper
  File "<frozen importlib._bootstrap_external>", line 907, in load_module
  File "<frozen importlib._bootstrap_external>", line 732, in load_module
  File "<frozen importlib._bootstrap>", line 265, in _load_module_shim
  File "<frozen importlib._bootstrap>", line 696, in _load
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/hooks/hook-pandas.py", line 15, in <module>
    hiddenimports = collect_submodules('pandas._libs')
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/utils/hooks/__init__.py", line 603, in collect_submodules
    if not is_package(package):
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/utils/hooks/__init__.py", line 483, in is_package
    return isolated.call(_is_package, module_name)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/isolated/_parent.py", line 372, in call
    return isolated.call(function, *args, **kwargs)
  File "/opt/anaconda3/lib/python3.7/site-packages/PyInstaller/isolated/_parent.py", line 247, in __exit__
    self._write_handle.flush()
BrokenPipeError: [Errno 32] Broken pipe
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-11-15 18:40

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

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