microsoft / jumpstart-agora-apps

A repository for hosting Jumpstart Agora industry sample applications
MIT License
23 stars 81 forks source link

ImportError: numpy.core.multiarray failed to import [contoso_manufacturing/developer/webapp-decode] #149

Open robertstarling opened 3 days ago

robertstarling commented 3 days ago

Hitting the following CrashLoopBackOff container runtime error when rebuilding jumpstartprod.azurecr.io/ag_mfg_webui:latest from the source code using contoso_manufacturing/developer/webapp-decode/Dockerfile


A module that was compiled using NumPy 1.x cannot be run in
NumPy 2.1.1 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 "/app/app.py", line 3, in <module>
    import cv2
  File "/usr/local/lib/python3.11/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/usr/local/lib/python3.11/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
AttributeError: _ARRAY_API not found
Traceback (most recent call last):
  File "/app/app.py", line 3, in <module>
    import cv2
  File "/usr/local/lib/python3.11/site-packages/cv2/__init__.py", line 181, in <module>
    bootstrap()
  File "/usr/local/lib/python3.11/site-packages/cv2/__init__.py", line 153, in bootstrap
    native_module = importlib.import_module("cv2")
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/importlib/__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ImportError: numpy.core.multiarray failed to import

Steps to reproduce:

The flask-app-deployment pods now fail with the error shown above.

robertstarling commented 3 days ago

Adding an explicit dependency in contoso_manufacturing\developer\webapp-decode\requirements.txt as follows appears to resolve the issue:

numpy==1.26.4
niachary commented 2 days ago

The line 'import cv2' was resulting in the error. As is mentioned in the resolution: If you are a user of the module, the easiest solution will be to downgrade to 'numpy<2'

Downgrading the numpy to 1.26.4 resolved the issue. Any version < 2.0.0 should also work: https://stackoverflow.com/questions/78636947/a-module-that-was-compiled-using-numpy-1-x-cannot-be-run-in-numpy-2-0-0-as-it-ma

robertstarling commented 2 days ago

Pull request with this fix is here: https://github.com/microsoft/jumpstart-agora-apps/pull/152