使用Dipy导入函数时遭遇numpy.float属性错误求助
问题:Dipy 1.3.0 结合 NumPy 1.24.4 出现 AttributeError: module 'numpy' has no attribute 'float'
使用Dipy库导入函数时触发如下错误:
AttributeError: module 'numpy' has no attribute 'float'. `np.float` was a deprecated alias for the builtin `float`. To avoid this error in existing code, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here. The aliases was originally deprecated in NumPy 1.20; for more details and guidance see the original release note at:https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations错误调用栈指向Dipy内部的
dipy.reconst.recspeed.remove_similar_vertices()方法,但自身代码库及回溯信息里都找不到np.float的使用痕迹,VS Code全局搜索也无相关结果。当前环境是numpy 1.24.4和dipy 1.3.0。
解决方案
升级Dipy版本(推荐):Dipy 1.3.0属于旧版本,未适配NumPy 1.24.x中移除
np.float等旧别名的改动。后续Dipy版本(如1.6.0及以上)已修复该兼容性问题,执行以下命令升级:pip install --upgrade dipy降级NumPy版本(临时方案):若暂时无法升级Dipy,可将NumPy降级至1.21.x及以下版本(该区间仍保留
np.float的兼容别名),执行命令:pip install numpy==1.21.6手动修改Dipy源码(应急手段):若上述方案均不可行,可找到Dipy安装目录下的
dipy/reconst/recspeed.py文件,将其中的np.float替换为float或np.float64。注意此方法会破坏包完整性,后续升级Dipy需重新修改,仅作临时应急用。
内容的提问来源于stack exchange,提问作者SillyWoodpecker6508
相关产品推荐
相关产品推荐

