我的python项目有以下导入列表:
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
以及用于分发项目的此规范文件:
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')
我使用此命令制作项目的exe文件:
pyinstaller Datamanager.spec
但是当我运行exe文件时,出现此错误:
ModuleNotFoundError: No module named 'sklearn.utils._cython_blas'
我应该在隐藏的导入部分中添加什么其他内容?
PyInstaller对每个Python模块都使用了钩子机制,但是有时它会丢失一些内部软件包,因此您需要手动提供它们。您可以使用--hidden- import添加sklearn缺少的模块。
--hidden- import
sklearn
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