You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PyInstaller打包Python脚本为exe后提示找不到win10toast模块

PyInstaller打包win10toast脚本时ModuleNotFoundError的解决方法

问题场景

执行命令 pyinstaller --onefile reminder.py 将包含 import time 和 from win10toast import ToastNotifier 的脚本打包为单文件exe,本地已安装win10toast模块,但运行exe时出现以下错误:

File "reminder.py", line 2, in <module>
ModuleNotFoundError: No module named 'win10toast'
[25352] Failed to execute script 'reminder' due to unhandled exception!

已尝试重装win10toast、更换Python解释器打包,问题未解决。

解决步骤

  • 强制指定隐藏依赖打包
    直接在打包命令中添加--hidden-import参数指定win10toast模块:

    pyinstaller --onefile --hidden-import win10toast reminder.py
    

    PyInstaller自动分析依赖时可能遗漏部分第三方库,该参数可强制将模块纳入打包范围。

  • 验证当前环境的依赖状态

    1. 确认打包时使用的Python环境已安装win10toast:
      pip list | findstr win10toast
      
      (Linux/macOS环境替换为 pip list | grep win10toast)
    2. 若使用虚拟环境,需确保打包前已激活对应环境。
  • 通过.spec文件手动配置依赖

    1. 先生成.spec配置文件:
      pyinstaller --onefile reminder.py
      
    2. 打开生成的reminder.spec文件,找到hiddenimports字段,修改为:
      hiddenimports=['win10toast']
      
    3. 基于修改后的.spec文件重新打包:
      pyinstaller reminder.spec
      
  • 检查模块安装路径匹配性
    执行以下命令查看win10toast的安装路径:

    pip show win10toast
    

    确认该路径在当前Python解释器的sys.path范围内,若不在,可尝试重新安装模块到解释器默认路径:

    python -m pip install win10toast
    

内容的提问来源于stack exchange,提问作者catbug

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 00:52:35