42

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?

2

11 Answers 11

64

Getting same error for numpy 2.0 as of March 18th 2025.

Current solution is :

pip install "numpy<2"
Sign up to request clarification or add additional context in comments.

4 Comments

Same error with numpy 2.0.2 on Oct 18, your current solution also did the trick for me.
This will install the latest version of numpy1. Worked for me, or else mention Numpy version.
This will also work pip install numpy==1.26.4. The latest version of numpy 1.
Make sure to restart kernel after running this command
28

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

3 Comments

This breaks numba for me, which is a dependency of a dependency rather than something I directly use :P github.com/numba/numba/issues/8615
Even though I am running torch and torch audio 2.2.2, I had to pin numpy to 1.24.1 to get whisper to work properly as a model from huggingface otherwise I was getting the numpy not found error. Very weird.
Instead of setting a fixed version for torch, it would be better to downgrade numpy to an older version. for example, pip3 install "numpy<2.x" # or "numpy<2". It's a better fail-proof method.
13

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.

1 Comment

Thank you for this. I'd say this should be the canonical first step before fiddling with specific package versions.
7

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.

2 Comments

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
You may want to look at setting up a dedicated Python environment for this project (with either virtual environments or something like conda / mamba). Not only will this allow you to install specific versions of packages and their (version specific) dependencies, but also to freeze those packages at those versions (preventing upgrades) and even package the environment for migration or redistribution to other machines with (more) guaranteed reproducibility. -- allowing you to maintain up to date packages in your main / system installation!
2

Upgrade pytorch.

At current time, pytorch 2.7.1 works fine with numpy 2.0.

1 Comment

I don't want to downgrade to numpy v1. This is exactly what I need! Thanks.
2

Instead of using

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

use this:

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

2 Comments

Can you provide more details?
RuntimeError: Could not infer dtype of numpy.float32
1

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.

Comments

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.

Comments

0

For me it was a Python versioning issue. When I ran the code with Python 3.10 I got the error, however, when using Python 3.8 everything worked fine.

So my advice is just be wary of the versions your repository/code relies on.

1 Comment

Only thing that worked
-1

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

Comments

-2

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

1 Comment

This answer does not address the issue the OP has regarding version incompatibility between different libraries. -- If you are certain it is an appropriate solution to the question posed then please expand you answer to give clear and detailed information on how to implement your solution and how it resolves the problem as described.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.