PyInstaller: a module is not included into --onefile, but works fine with --onedir

后端 未结 2 646
执念已碎
执念已碎 2021-02-05 17:59

I\'m using PyInstaller to bundle my application into one .exe file. The problem is that it works fine with --onedir option, but can\'t find a module when built with --onefile.

2条回答
  •  攒了一身酷
    2021-02-05 18:58

    I had the same error. The solution is to create a hook for sklearn. Generally, u need to create a hook file like this

    hiddenimports = ['sklearn.utils.sparsetools._graph_validation'] 
    

    and save this in a file with name hook-modulename.py in the same folder. But this will import only _graph_validation. This might lead to error for another module. Best to import all the submodules in a package by

    from hookutils import collect_submodules
    hiddenimports = collect_submodules('sklearn') 
    

    and save it to a hook file in the same folder. For me, I had to create 2 hook file. one for sklearn and one for scipy.

    from hookutils import collect_submodules
    hiddenimports = collect_submodules('scipy') 
    

    after saving them I used below command to run

    pyinstaller --additional-hooks-dir=. myfile.py

    for better understanding follow this link.

提交回复
热议问题