Odin
Odin

Reputation: 376

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

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?

Upvotes: 30

Views: 91525

Answers (9)

engine-erin-g
engine-erin-g

Reputation: 1

When importing torch you get the following warning:

A module that was compiled using NumPy 1.x cannot be run in NumPy 2.0.2 as it may crash... 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.

Solution: pip install 'numpy<2' and don't forget to restart the Kernel.

Upvotes: 0

Abhishek Barnwal
Abhishek Barnwal

Reputation: 1

Faced same error while writing code in Notebook Fix : Restart the Kernel.

Upvotes: 0

Talha Tayyab
Talha Tayyab

Reputation: 27575

Getting same error for numpy 2.0 as of October 25th 2024.

Current solution is :

pip install "numpy<2"

Upvotes: 33

heatblast
heatblast

Reputation: 1

I faced the same issue. Simply restarting the kernel should help.

Upvotes: -2

Prakash tirumalaseti
Prakash tirumalaseti

Reputation: 21

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.

Upvotes: 2

NPE_Exception
NPE_Exception

Reputation: 381

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.

Upvotes: 11

Otabek
Otabek

Reputation: 41

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

Upvotes: 1

Drwaish
Drwaish

Reputation: 281

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

Upvotes: 28

Odin
Odin

Reputation: 376

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.

Upvotes: 6

Related Questions