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

.

背景

在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

问题解决~

预祝大家写代码顺利~

.

你可能感兴趣的:(Package,numpy,python,深度学习)