• pyinstaller 打包 sentry_sdk 出现 ModuleNotFoundError 的解决方法


    问题背景

    我使用 pyqt 在开发一款跨平台的文件检索工具,使用 pyinstaller 打包依赖。为了更好的统计程序的 崩溃日志,决定使用 sentry 来自动化收集。

    使用共有云的方案,安装 sentry 官方给的 demo 程序很快就跑通了。使用 pyinstaller 可以成功打包,但程序无法启动,日志报错为

    解决过程

    ModuleNotFoundError: No module named 'sentry_sdk.integrations.logging

    根据错误提示在 pyinstaller脚本中加入隐含导入

    pyinstaller --hidden-import sentry_sdk.integrations.logging

    再次打包并运行,又提示缺乏 sentry_sdk.integrations.stdlib, 手动将此依赖写入 pyinstaller 脚本中再次提示缺乏sentry_sdk.integrations.deque

     

     

    没完没了了,通过错误关键字找到了这个 pyinstaller-issue-4755 引到了 pyinstaller 的官方文档

    我尝试使用 pyinstaller --hidden-import sentry_sdk.integrations.* 却发现 pyinstaller 在打包时提示 无法分析 sentry_sdk.integrations.*

     

     

    中间搜索了很多,最后得到此方案

    在 pyinstaller 同级目录下编辑一个文件 hook-sentry_sdk.integrations.py写入这些东西

    hiddenimports = [
        'sentry_sdk.integrations.argv',
        'sentry_sdk.integrations.logging',
        'sentry_sdk.integrations.stdlib',
        'sentry_sdk.integrations.threading',
        'sentry_sdk.integrations.atexit',
        'sentry_sdk.integrations.rq',
        'sentry_sdk.integrations.trytond',
        'sentry_sdk.integrations.excepthook',
        'sentry_sdk.integrations.modules',
        'sentry_sdk.integrations.dedupe'
    ]

    为 pyinstaller 增加一条打包参数 

    --additional-hooks-dir .

    问题解决了

    参考链接

    PyInstaller 系列 - Hook 机制

  • 相关阅读:
    fastdfs部署及官网
    fasrdfs在spring cloud中的使用
    面包屑的查询
    SpringCloud中使用ES使用课程上下线
    Redis中在项目中的使用
    树结构Tree查询
    平凡的世界 田晓霞的日记 摘抄

    英语积累
    英语学习第四天
  • 原文地址:https://www.cnblogs.com/albertofwb/p/13032114.html
Copyright © 2020-2023  润新知