9

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?

Odin
  • 156
  • 1
  • 1
  • 7
  • [`numpy` upgraded its `c` API between 1.19 and 1.20 in a mildly non backwards compatible way and it's taken a while to get everyone on the same page.](https://github.com/numba/numba/issues/7339) [New `numba` versions support `numpy` >1.20](https://github.com/numba/numba/issues/6182) but I'm not sure if `librosa` has gotten with the program yet. If not you [might need to keep everything in an older version](https://stackoverflow.com/questions/67331302/not-able-to-install-librosa) – Daniel F Mar 31 '22 at 08:52
  • I did set up my raspberry pi completely fresh and installed every package with the same version as they are on my laptop. While my code runs without any problems on my laptop it still throws the same exact error as before when running on my raspberry pi. How is this possible? – Odin Mar 31 '22 at 14:04

4 Answers4

10

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

Fedor
  • 17,146
  • 13
  • 40
  • 131
Drwaish
  • 101
  • 1
  • 4
  • 1
    This breaks numba for me, which is a dependency of a dependency rather than something I directly use :P https://github.com/numba/numba/issues/8615 – TeamDman Mar 10 '23 at 03:43
5

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.

Odin
  • 156
  • 1
  • 1
  • 7
  • 1
    Came across the same error with Pytorch 1.12.1. I downgraded to version 1.11.0 since older version don't seem to exist anymore and it worked – zanga Sep 01 '22 at 14:30
0

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

Otabek
  • 31
  • 4
0

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.

NPE_Exception
  • 111
  • 2
  • 5