Cannot deploy Python app to Azure: Wheels build breaks with fatal error: "Python.h: No such file or directory"
I created a Python function, which uses the Python package cvxpy version 1.2.1. I added the line "cvxpy>=1.1.18" to my requirements.txt
When deploying to Azure, the deployment fails with the following errors:
gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O3 -Wall -fPIC -Icvxpy/cvxcore/src/ -Icvxpy/cvxcore/python/ -Icvxpy/cvxcore/include/ -I/opt/python/3.9.7/include/python3.9 -I/tmp/pip-build-env-vakve0tr/overlay/lib/python3.9/site-packages/numpy/core/include -c cvxpy/cvxcore/python/cvxcore_wrap.cxx -o build/temp.linux-x86_64-cpython-39/cvxpy/cvxcore/python/cvxcore_wrap.o -O3 -std=c++11 -Wall -pedantic -Wextra -Wno-unused-parameter
cvxpy/cvxcore/python/cvxcore_wrap.cxx:178:21: fatal error: Python.h: No such file or directory
# include <Python.h>
^
compilation terminated.
error: command '/usr/bin/gcc' failed with exit code 1
This errors normally occur, when python3-dev is not installed. I cannot install this package myself as I have no access to the Azure build server (I am using the recommended remote build). How can I solve this issue?
Here are the complete steps to reproduce the issue:
- Execute in command line: "func init TestFunction --python"
- Execute in command line: "cd TestFunction"
- Execute in command line: "func new --name HttpExample --template "HTTPtrigger" --authlevel "anonymous"
- Add requirement "cvxpy>=1.1.18" to your requirements.txt.
- Deploy to Azure using: "func azure functionapp publish <your-azure-function-name> --additional-packages python3-dev libpython3-dev"
You may need to create a virtual environment using "python -m venv .venv".
Please note, that adding --build local to the func azure functionapp publish command will fail with the following message:
There was an error restoring dependencies. WARNING: You are using pip version 21.2.3; however, version 22.2.2 is available.
You should consider upgrading via the '....venv\Scripts\python.exe -m pip install --upgrade pip' command.
ERROR: cannot install cvxpy-1.2.1 dependency: binary dependencies without wheels are not supported when building locally. Use the "--build remote" option to build dependencies on the Azure Functions build server, or "--build-native-deps" option to automatically build and configure the dependencies using a Docker container. More information at https://aka.ms/func-python-publish
Best regards,
Simon