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?
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.
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
Instead of using
spect_tensor = torch.from_numpy(spect).double()
use this
spect_tensor = torch.tensor(spect).double()
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.
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.
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?
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.
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
Instead of using
spect_tensor = torch.from_numpy(spect).double()
use this
spect_tensor = torch.tensor(spect).double()
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.
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.