Azure Python Function fails to load numpy after virtual environment was updated to Ubuntu 20.04
Yesterday I started to have a strange error in an Azure Python Function:
Result: Failure
Exception: ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.6 from "/usr/local/bin/python"
* The NumPy version is: "1.19.5"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
. Troubleshooting Guide: https://aka.ms/functions-modulenotfound
Stack: File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/dispatcher.py", line 275, in _handle__function_load_request
func_request.metadata.entry_point)
File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 34, in call
raise extend_exception_message(e, message)
File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/utils/wrappers.py", line 32, in call
return func(*args, **kwargs)
File "/azure-functions-host/workers/python/3.6/LINUX/X64/azure_functions_worker/loader.py", line 76, in load_function
mod = importlib.import_module(fullmodname)
File "/usr/local/lib/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 941, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/home/site/wwwroot/MyFuncName/__init__.py", line 5, in <module>
from mycustommodule import mycustomsubmodule
File "/home/site/wwwroot/mycustommodule/mycustomsubmodule.py", line 6, in <module>
from .anothersubmodule import module_xyz
File "/home/site/wwwroot/mycustommodule/module_xyz.py", line 7, in <module>
from numpy import isnan
File "/home/site/wwwroot/.python_packages/lib/site-packages/numpy/__init__.py", line 140, in <module>
from . import core
File "/home/site/wwwroot/.python_packages/lib/site-packages/numpy/core/__init__.py", line 48, in <module>
raise ImportError(msg)
I am using Python 3.6 because on of my packages depends on it. Numpy version 1.19.5 is compatible with Python 3.6. This is my full requirements file:
azure-functions==1.6.0
azure-identity==1.5.0
azure-keyvault-secrets==4.2.0
opencensus-ext-azure==1.0.7
ortools==8.2.8710
numpy==1.19.5
pandas==1.1.5
pyodbc==4.0.30
sqlalchemy==1.3.23
This problem started to appear yesterday. From Azure DevOps deployment logs, I can see that the virtual environment OS changed from Ubuntu 18.04 to 20.04 and that's when the problems started.
I can file a bug request on this, but what is the correct repository? Azure Functions host runtime or Python worker runtime repository?
EDIT: Note that the error is caused by the module numpy.core._multiarray_umath. When I open the Function files in VS Code, I can see that .python_packages/lib/site-packages/numpy/core contains file _multiarray_umath.cpython-37m-x86_64-linux-gnu.so, which seems to refer to the wrong Python version.
EDIT 2: Bug report filed: 1860