joeweiss / birdnetlib

A python api for BirdNET-Lite and BirdNET-Analyzer
https://joeweiss.github.io/birdnetlib/
Apache License 2.0
39 stars 13 forks source link

NumPy conflict for Analyzer() #115

Open herbbetz opened 2 months ago

herbbetz commented 2 months ago

Dear Mr. Weiss, I just tried your code from 6.2 of https://github.com/kahst/BirdNET-Analyzer. My system is bookworm 64bit on RPi4B. I installed all the libraries into a venv and started your example.py from there. It says:

A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.0.0 as it may crash. To support both 1.x and 2.x
versions of NumPy, modules must be compiled with NumPy 2.0.
Some module may need to rebuild instead e.g. with 'pybind11>=2.12'.

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.

Traceback (most recent call last):  File "/home/pi/audiostation/birdnet.py", line 7, in <module>
    analyzer = Analyzer()
  File "/home/pi/herbvenv/lib/python3.11/site-packages/birdnetlib/analyzer.py", line 122, in __init__
    self.load_model()
  File "/home/pi/herbvenv/lib/python3.11/site-packages/birdnetlib/analyzer.py", line 386, in load_model
    self.interpreter = tflite.Interpreter(
  File "/home/pi/herbvenv/lib/python3.11/site-packages/tflite_runtime/interpreter.py", line 464, in __init__
    self._interpreter = _interpreter_wrapper.CreateWrapperFromFile(
AttributeError: _ARRAY_API not found
ImportError: numpy.core.multiarray failed to import

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/pi/audiostation/birdnet.py", line 7, in <module>
    analyzer = Analyzer()
               ^^^^^^^^^^
  File "/home/pi/herbvenv/lib/python3.11/site-packages/birdnetlib/analyzer.py", line 122, in __init__
    self.load_model()
  File "/home/pi/herbvenv/lib/python3.11/site-packages/birdnetlib/analyzer.py", line 386, in load_model
    self.interpreter = tflite.Interpreter(
                       ^^^^^^^^^^^^^^^^^^^
  File "/home/pi/herbvenv/lib/python3.11/site-packages/tflite_runtime/interpreter.py", line 464, in __init__
    self._interpreter = _interpreter_wrapper.CreateWrapperFromFile(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SystemError: <built-in method CreateWrapperFromFile of PyCapsule object at 0x7f6f7a95c0> returned a result with an exception set

What should I do? Thanks for any hints, H.Betz (Germany)

MichaelPWalter commented 2 months ago

Same issue today. Running on RPi 5 using Bookworm 64-bit. I believe the issue lies with NumPy 2.0. I will try to downgrade my version of NumPy to 1.26.4 once ive figured out how to do that. Viele Gruesse, Michael

joeweiss commented 2 months ago

Thanks for the reports @herbbetz and @MichaelPWalter. I'll take a look in the next few days and see what needs to change for NumPy 2.

Installing birdnetlib itself doesn't directly install numpy, but it is expected as a dependency from BirdNET-Analyzer. I'll have to investigate.

To downgrade (if using pip), this should work:

pip uninstall numpy -y
pip install numpy==1.26.4
MichaelPWalter commented 2 months ago

I have tried connecting to RPi with ssh and running sudo apt install python3-numpy but this had no effect. I will reinstall BirdNet pi from a different fork that advertises RPi5 compatibility curl -s https://raw.githubusercontent.com/Nachtzuster/BirdNET-Pi/main/newinstaller.sh | bash Just tested and confirm works !