How to solve the pytorch RuntimeError: Numpy is not available without upgrading numpy to the latest version because of other dependencies

Question:

I am running a simple CNN using Pytorch for some audio classification on my Raspberry Pi 4 on Python 3.9.2 (64-bit). For the audio manipulation needed I am using librosa. librosa depends on the numba package which is only compatible with numpy version <= 1.20.

When running my code, the line

spect_tensor = torch.from_numpy(spect).double()

throws the RuntimeError:

RuntimeError: Numpy is not available

Searching the internet for solutions I found upgrading Numpy to the latest version to resolve that specific error, but throwing another error, because Numba only works with Numpy <= 1.20.

Is there a solution to this problem which does not include searching for an alternative to using librosa?

Asked By: Odin

||

Answers:

Just wanted to give an update on my situation. I downgraded torch to version 0.9.1 which solved the original issue. Now OpenBLAS is throwing a warning because of an open MPLoop. But for now my code is up and running.

Answered By: Odin

This will be easily solved by upgrading numpy….
When I face this error, that time numpy version 1.22 was installed….
I update version to 1.24.1 using this command

pip install numpy==1.24.1

Error Resolved

Answered By: Drwaish

Instead of using
spect_tensor = torch.from_numpy(spect).double()
use this
spect_tensor = torch.tensor(spect).double()

Answered By: Otabek

For some who may be facing this issue in a brand new python environment, you may just have to restart Jupyter Notebook. I received this error simply because I had started up notebook, and then installed numpy in my python environment after realizing it was not previously installed.

If you’ve done this, just kill the jupyter session and restart. It will pick up the new numpy install.

Answered By: NPE_Exception

Issue : Faced same error while writing code for LLMs.(NumPy is not available)
Fix : Restart the Kernel. (Thanks to NPE_Exception for clue, credit goes to this member)
Details : Cause of issue is due to installing packages as found missing while writing code in note book . Looks like should not be done that way. It needs kernel restart to get reference.

Categories: questions Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.