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

PyInstaller打包仅含dist-info,缺失pandasgui和qtstylish包求助

解决PyInstaller打包pandasgui/qtstylish时缺失包文件的问题

问题描述

打包多依赖项目时,PyInstaller仅包含pandasgui和qtstylish的dist-info目录,缺失包本身的代码与资源文件,运行生成的tool.exe时触发以下错误:

FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\...\\AppData\\Local\\Temp\\_MEI308162\\qtstylish\\compiled/dark.qss'

使用的打包命令:

pyinstaller --onedir --windowed --collect-submodules pandasgui --name tool -p . tool/main.py

相关依赖配置:

pandasgui==0.2.14 ; python_version >= "3.10" and python_version < "3.11" \
--hash=sha256:22eac39cb44815091565862ecd7af6ac46fa383a7269755ad7c105585a1b988a
qtstylish==0.1.5 ; python_version >= "3.10" and python_version < "3.11" \
--hash=sha256:3402562d8b92d0de3706a8478323a998bfe92f29572bdf07ef205895b1a1a29a

解决方案

1. 强制收集完整包资源(最简方案)

--collect-submodules仅收集包的子模块代码,无法覆盖资源文件,替换为--collect-all参数强制收集包的所有文件:

pyinstaller --onedir --windowed --collect-all pandasgui --collect-all qtstylish --name tool -p . tool/main.py

2. 手动配置spec文件(精准控制)

若上述方法无效,可通过spec文件手动指定资源路径:

  • 生成基础spec文件:
pyi-makespec --onedir --windowed --name tool -p . tool/main.py
  • 打开tool.spec,在datas列表中添加资源映射(替换为你的实际包安装路径,可通过pip show qtstylish查看Location字段):
datas=[
    (r"C:\Python310\Lib\site-packages\qtstylish\compiled", "qtstylish/compiled"),
    (r"C:\Python310\Lib\site-packages\pandasgui", "pandasgui"),
],
  • 基于spec文件打包:
pyinstaller tool.spec

3. 补充隐藏导入(针对动态加载模块)

若存在PyInstaller未检测到的动态导入模块,在spec文件的hiddenimports中添加:

hiddenimports=[
    "qtstylish",
    "qtstylish.compiled",
    "pandasgui",
    "pandasgui.widgets",
    "pandasgui.views",
],

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.24 23:52:37