【问题标题】:pyinstaller adding nested modules in hidden imports is not workingpyinstaller 在隐藏导入中添加嵌套模块不起作用
【发布时间】:2020-08-05 13:32:18
【问题描述】:

我正在使用 pyinstaller 将“.py”脚本转换为 exe 文件。该脚本采用一些 CLI 参数并在其上运行 scikit-learn 和 keras 模型并返回预测。当像“python3 predict.py”一样执行时,“.py”工作正常。 但是,当我使用时:

pyinstaller --onefile predict.py

它给出了这个错误:

ModuleNotFoundError: No module named 'sklearn.neighbors._typedefs'

但是当我做 pip3 list 时,我可以清楚地看到那里安装了 scikit-learn。 在搜索堆栈溢出后,我了解到 pyinstaller 在获取二级依赖项时遇到问题,可以通过在隐藏导入中添加库来解决。我是这样做的:

a = Analysis(['predict.py'],
             pathex=['/Users/mac/Desktop/Fiverr/Clothes_Classification/Scripts'],
             binaries=[],
             datas=[],
             hiddenimports=['sklearn.neighbors._typedefs'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)

但同样的错误仍然存​​在。 keras 的模型给出的输出很好,但 sklearn 的所有模型都失败了。另外,我正在使用 pickle 加载 sklearn 的模型,并使用 load_model 从 keras 加载 keras 模型。

我是这样执行的:

./predict "/Users/mac/Desktop/Fiverr/Clothes_Classification/Dataset/Images/5336-0010.jpg" "/Users/mac/Desktop/Fiverr/Clothes_Classification/Scripts/Models/"

其中给出了 sys.argv 在程序中使用的 2 个 CLI。我认为它们没有问题。

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: python scikit-learn pyinstaller


    【解决方案1】:

    .spec 文件应修改为 hidden-import typdefs(注意缺少下划线) hiddenimports=['sklearn.neighbors.typedefs'],

    而不是 hiddenimports=['sklearn.neighbors._typedefs'], 正如错误可能暗示的那样

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 2019-12-05
      • 2023-03-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多