Package | 解决 RuntimeError: Numpy is not available. Failed to initialize NumPy against version 0xf

在Docker环境中配置深度学习实验时,遇到Numpy不可用的问题。通过详细错误提示,找到并解决了Numpy版本与PyTorch不兼容的故障。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

.

背景

在docker里配置实验环境,根据repo中的指令"pip install -r requirement.txt",安装完必要的包,具体信息如下。

torch == 1.8.0
opencv_python == 4.5.2.52
trimesh == 3.9.8
numpy == 1.19.2
pyhocon == 0.3.57
icecream == 2.1.0
tqdm == 4.50.2
scipy == 1.7.0
PyMCubes == 0.1.2

运行训练时,出现报错如下,非常简略的报错信息:

RuntimeError: Numpy is not available

根据该报错信息查到几篇博客,其中的方法都不太适用。于是重看报错的信息,发现有一行User Warning,内容如下:

/opt/conda/lib/python3.8/site-packages/torch/_masked/__init__.py:223: UserWarning: Failed to initialize NumPy: module compiled against API version 0xf but this version of numpy is 0xd (Triggered internally at /opt/pytorch/pytorch/torch/csrc/utils/tensor_numpy.cpp:68.)

.

解决方案

根据User Warning的信息搜到有效解决方案,原答案链接:github-answer

该报错原因是当前numpy版本和环境不匹配,需要对其进行升级。指令如下:

pip install numpy --upgrade

问题解决~

预祝大家写代码顺利~

.

RuntimeError: SetPrecisionMode:build/CMakeFiles/torch_npu.dir/compiler_depend.ts:155 NPU function error: at_npu::native::AclSetCompileopt(aclCompileOpt::ACL_PRECISION_MODE, precision_mode), error code is 500001 [ERROR] 2025-07-07-15:58:56 (PID:4001235, Device:0, RankID:-1) ERR00100 PTA call acl api failed [Error]: The internal ACL of the system is incorrect. Rectify the fault based on the error information in the ascend log. EC0010: [PID: 4001235] 2025-07-07-15:58:56.704.356 Failed to import Python module [AttributeError: `np.float_` was removed in the NumPy 2.0 release. Use `np.float64` instead..]. Solution: Check that all required components are properly installed and the specified Python path matches the Python installation directory. (If the path does not match the directory, run set_env.sh in the installation package.) TraceBack (most recent call last): AOE Failed to call InitCannKB[FUNC:Initialize][FILE:python_adapter_manager.cc][LINE:47] Failed to initialize TeConfigInfo. [GraphOpt][InitializeInner][InitTbeFunc] Failed to init tbe.[FUNC:InitializeTeFusion][FILE:tbe_op_store_adapter.cc][LINE:1889] [GraphOpt][InitializeInner][InitTeFusion]: Failed to initialize TeFusion.[FUNC:InitializeInner][FILE:tbe_op_store_adapter.cc][LINE:1856] [SubGraphOpt][PreCompileOp][InitAdapter] InitializeAdapter adapter [tbe_op_adapter] failed! Ret [4294967295][FUNC:InitializeAdapter][FILE:op_store_adapter_manager.cc][LINE:79] [SubGraphOpt][PreCompileOp][Init] Initialize op store adapter failed, OpsStoreName[tbe-custom].[FUNC:Initialize][FILE:op_store_adapter_manager.cc][LINE:120] [FusionMngr][Init] Op store adapter manager init failed.[FUNC:Initialize][FILE:fusion_manager.cc][LINE:115] PluginManager InvokeAll failed.[FUNC:Initialize][FILE:ops_kernel_manager.cc][LINE:83] OpsManager initialize failed.[FUNC:InnerInitialize][FILE:gelib.cc][LINE:259] GELib::InnerInitialize failed.[FUNC:Initialize][FILE:gelib.cc][LINE:184] GEInitialize failed.[FUNC:GEInitialize][FILE:ge_api.cc][LINE:371] [Initialize][Ge]GEInitialize failed. ge result = 4294967295[FUNC:ReportCallError][FILE:log_inner.cpp][LINE:161] [Init][Compiler]Init compiler failed[FUNC:ReportInnerError][FILE:log_inner.cpp][LINE:145] [Set][Options]OpCompileProcessor init failed![FUNC:ReportInnerError][FILE:log_inner.cpp][LINE:145]
最新发布
07-08
纠错5: python Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import whisper >>> from transformers import MarianMTModel, MarianTokenizer >>> whisper.load_model("small") A module that was compiled using NumPy 1.x cannot be run in NumPy 2.1.3 as it may crash. To support both 1.x and 2.x versions of NumPy, modules must be compiled with NumPy 2.0. Some module may need to rebuild instead e.g. with 'pybind11>=2.12'. If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2' or try to upgrade the affected module. We expect that some modules will need time to support NumPy 2. Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\bili_translator\venv\lib\site-packages\whisper\__init__.py", line 150, in load_model checkpoint = torch.load(fp, map_location=device) File "D:\bili_translator\venv\lib\site-packages\torch\serialization.py", line 809, in load return _load(opened_zipfile, map_location, pickle_module, **pickle_load_args) File "D:\bili_translator\venv\lib\site-packages\torch\serialization.py", line 1172, in _load result = unpickler.load() File "D:\bili_translator\venv\lib\site-packages\torch\_utils.py", line 169, in _rebuild_tensor_v2 tensor = _rebuild_tensor(storage, storage_offset, size, stride) File "D:\bili_translator\venv\lib\site-packages\torch\_utils.py", line 147, in _rebuild_tensor t = torch.tensor([], dtype=storage.dtype, device=storage._untyped_storage.device) D:\bili_translator\venv\lib\site-packages\torch\_utils.py:147: UserWarning: Failed to initialize NumPy: _ARRAY_API not found (Triggered internally at ..\torch\csrc\utils\tensor_numpy.cpp:84.) t = torch.tensor([], dtype=storage.dtype, device=storage._untyped_storage.device) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "D:\bili_translator\venv\lib\site-packages\whisper\__init__.py", line 158, in load_model model.set_alignment_heads(alignment_heads) File "D:\bili_translator\venv\lib\site-packages\whisper\model.py", line 282, in set_alignment_heads mask = torch.from_numpy(array).reshape( RuntimeError: Numpy is not available
03-23
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值