导入h5py触发numpy AttributeError:module 'numpy' has no attribute 'typeDict'
问题:导入kuti.image_utils触发h5py导入,报AttributeError: module 'numpy' has no attribute 'typeDict'
完整报错回溯
AttributeError Traceback (most recent call last) /home/ack253/neuroaesthetics/ava-mlsp/predict_mlsp_wide.ipynb Cell 5 line 2 1 import pandas as pd, numpy as np, os ----> 2 from kuti import image_utils as img File ~/.local/lib/python3.8/site-packages/kuti/__init__.py:8 5 import warnings 6 warnings.filterwarnings('ignore',category=FutureWarning) ----> 8 from . import generic, tensor_ops, image_utils, generators, model_helper, applications 10 # remove tensorflow warnings 11 import logging File ~/.local/lib/python3.8/site-packages/kuti/generic.py:10 8 import numpy as np, pandas as pd 9 import multiprocessing as mp ---> 10 import os, scipy, h5py, time, sys 11 import urllib, shutil, subprocess 12 from munch import Munch File ~/.local/lib/python3.8/site-packages/h5py/__init__.py:46 37 _warn(("h5py is running against HDF5 {0} when it was built against {1}, " 38 "this may cause problems").format( 39 '{0}.{1}.{2}'.format(*version.hdf5_version_tuple), 40 '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple) ... 318 return Tester --> 320 raise AttributeError("module {!r} has no attribute " 321 "{!r}".format(__name__, attr)) AttributeError: module 'numpy' has no attribute 'typeDict'
原因分析
numpy.typeDict是旧版本numpy的属性,在numpy 1.20及以上版本中已被移除,替换为numpy.dtypeDict。报错是因为当前安装的h5py版本过旧,不兼容你使用的numpy新版本。
解决办法
- 升级h5py到兼容版本:在终端执行命令:
pip install --upgrade h5py - 锁定numpy兼容版本(可选):如果项目依赖旧版numpy特性,可安装适配的numpy版本(如1.19.x系列):
pip install numpy==1.19.5 - 检查虚拟环境:确认当前使用的虚拟环境正确,避免全局包与虚拟环境包版本冲突。
内容的提问来源于stack exchange,提问作者Alison
相关产品推荐
相关产品推荐

