Pyinstaller ; ModuleNotFoundError: No module named 'sklearn.utils._cython_blas'

一个人想着一个人 提交于 2020-06-09 13:43:03

问题


I have this import list for my python project:

import pandas as pd
import time
import sqlalchemy
from sklearn.ensemble import RandomForestClassifier
import pandas as pd
import numpy as np
from sqlalchemy import Column, String, Float, Integer, SmallInteger, MetaData
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy.orm import sessionmaker

And this spec file for distribution of the project:

import sys
sys.setrecursionlimit(5000)

block_cipher = None


a = Analysis(['DataManager.py'],
             pathex=['E:\\ForexPredictor'],
             binaries=[],
             datas=[],
             hiddenimports=['cython','pymysql','pandas._libs.tslibs.timedeltas','sklearn.neighbors.typedefs','sklearn.utils.typedefs'],
             hookspath=[],
             runtime_hooks=[],
             excludes=[],
             win_no_prefer_redirects=False,
             win_private_assemblies=False,
             cipher=block_cipher,
             noarchive=False)
pyz = PYZ(a.pure, a.zipped_data,
             cipher=block_cipher)
exe = EXE(pyz,
          a.scripts,
          [],
          exclude_binaries=True,
          name='DataManager',
          debug=False,
          bootloader_ignore_signals=False,
          strip=False,
          upx=True,
          console=True )
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               strip=False,
               upx=True,
               name='DataManager')

And I use this command to make exe file of the project:

pyinstaller Datamanager.spec

But when I run the exe file it gives this error:

ModuleNotFoundError: No module named 'sklearn.utils._cython_blas'

What other things should I add to the hidden imports part?


回答1:


PyInstaller uses a hook mechanism for each Python module, but sometimes it misses some internal packages so you need to provide them manually. You can use --hidden-import to add sklearn's missing modules.

pyinstaller -F --hidden-import="sklearn.utils._cython_blas" --hidden-import="sklearn.neighbors.typedefs" --hidden-import="sklearn.neighbors.quad_tree" --hidden-import="sklearn.tree._utils" Datamanager.py



回答2:


Add

import sklearn.utils._cython_blas

and maybe

import sklearn.neighbors.typedefs
import sklearn.neighbors.quad_tree
import sklearn.tree
import sklearn.tree._utils

to your code.




回答3:


Have you tried reading the documentation regarding the use of .spec-files? https://pyinstaller.readthedocs.io/en/stable/spec-files.html#using-spec-files

I don't know if it's the issue, but where is your *.py-file in the command for creating an .exe-file? As far as I know you have to give pyinstaller a .py-file for it to create a program.



来源:https://stackoverflow.com/questions/57108026/pyinstaller-modulenotfounderror-no-module-named-sklearn-utils-cython-blas

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!