简体   繁体   English

pyinstaller 在隐藏导入中添加嵌套模块不起作用

[英]pyinstaller adding nested modules in hidden imports is not working

I am using pyinstaller to convert a ".py" script to exe file.我正在使用 pyinstaller 将“.py”脚本转换为 exe 文件。 The script takes some CLI parameters and runs scikit-learn and keras models on it and returns the predictions.该脚本采用一些 CLI 参数并在其上运行 scikit-learn 和 keras 模型并返回预测。 The '.py' is working fine when being executed like "python3 predict.py".当像“python3 predict.py”一样执行时,“.py”工作正常。 But, when I use:但是,当我使用:

pyinstaller --onefile predict.py

It is giving this error:它给出了这个错误:

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

But when I do pip3 list, I can clearly see scikit-learn installed there.但是当我做 pip3 list 时,我可以清楚地看到 scikit-learn 安装在那里。 After searching on stack overflow I have understood that pyinstaller has trouble while getting second-level dependencies and that can be solved by adding the library in hidden imports.在搜索堆栈溢出后,我了解到 pyinstaller 在获取二级依赖项时遇到问题,可以通过在隐藏导入中添加库来解决。 i have done that like this:我已经这样做了:

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)

but the same error is still there.但同样的错误仍然存在。 The model from keras is giving output just fine but all models of sklearn are failing.来自 keras 的 model 给 output 就好了,但是 sklearn 的所有模型都失败了。 Also, I am using pickle to load sklearn's models and load_model from keras to load keras models.另外,我正在使用 pickle 加载 sklearn 的模型和 load_model 从 keras 加载 keras 模型。

I am executing it like this:我是这样执行的:

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

where 2 CLI are given that are used by sys.argv in the program.其中给出了 sys.argv 在程序中使用的 2 个 CLI。 There is no issue with them I think.我认为他们没有问题。

Any help will be much appreciated.任何帮助都感激不尽。 Thanks!谢谢!

The.spec file should be modified to hidden-import typdefs (notice the missing underscore) hiddenimports=['sklearn.neighbors.typedefs'], .spec 文件应该修改为 hidden-import typdefs (注意缺少下划线) hiddenimports=['sklearn.neighbors.typedefs'],

and not hiddenimports=['sklearn.neighbors._typedefs'], as the error might suggest而不是hiddenimports=['sklearn.neighbors._typedefs'],因为错误可能暗示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM