Oryx Build unable to build wheel for pycairo

Don Zhu 35 Reputation points
2023-05-05T22:01:01.1333333+00:00

I've run into deployment failures for my Flask app to Azure Web Apps recently. Was hoping to get some advice on how to remediate the issue.

Steps to recreate problem:

  • Create a GitHub repo and create a new file app.py with the following Flask Python code:
from flask import Flask
app = Flask(__name__)

@app.route("/")
    def hello():
        return "Hello World!"

if __name__ == "__main__":
    app.run()
  • Add another file requirements.txt
flask==2.1.0
flask-talisman==0.7.0
flask-session==0.4.0
#flask-cors
pandas==1.3.0
datetime
pyodbc==4.0.31
sqlalchemy==2.0.8
requests==2.25.0
msal==1.15.0
envelopes==0.4
adal==1.2.5
cryptography==3.4.8
pypdf==3.6.0
bleach==6.0.0
xhtml2pdf==0.2.9
  • Create a new Azure Web Apps instance for Linux-Python 3.8 in Canada Central or US East
  • Connect it with GitHub with Continuous Integration turned on so that changes in this repository will invoke the new deploy workflow Azure places into the repo
  • Navigate to the Actions tab on GitHub and you will notice the build steps complete successfully on GitHub
  • After the steps complete, the files are sent to Azure in a second Deploy job
  • Oryx takes over and performs a second build job on Azure's side and fails
  • The parts of the log detailing what failed reads as follows:

Building wheels for collected packages: pycairo Building wheel for pycairo (pyproject.toml): started Building wheel for pycairo (pyproject.toml): finished with status 'error' error: subprocess-exited-with-error

Building wheel for pycairo (pyproject.toml) did not run successfully. exit code: 1 lines of output] running bdist_wheel running build running build_py creating build creating build/lib.linux-x86_64-cpython-38 creating build/lib.linux-x86_64-cpython-38/cairo copying cairo/init.py -> build/lib.linux-x86_64-cpython-38/cairo copying cairo/init.pyi -> build/lib.linux-x86_64-cpython-38/cairo copying cairo/py.typed -> build/lib.linux-x86_64-cpython-38/cairo running build_ext Package cairo was not found in the pkg-config search path. Perhaps you should add the directory containing `cairo.pc' to the PKG_CONFIG_PATH environment variable No package 'cairo' found Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.15.10']' returned non-zero exit status 1. [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for pycairo Failed to build pycairo ERROR: Could not build wheels for pycairo, which is required to install pyproject.toml-based projects

The python dependency xhtml2pdf requires the python dependency pycairo which requires the OS-level package cairo. According to the docs on https://pycairo.readthedocs.io/en/latest/getting_started.html, it seems that the container running Oryx Build is missing cairo >= 1.15.10 thus failing.

This deployment issue hasn't occurred before with the same dependencies. It was only discovered recently (start of May).

I've tried to set the PRE_BUILD_COMMAND to apt-get install cairo or similar but these operations require permission elevation. Adding the install commands to the yaml workflow file shows that the Ubuntu-latest docker containers on GitHub's side contains the package but Oryx Build steps don't run on these containers - they run on Azure's side.

Maybe I'm missing something. Application runs fine locally. Any expert advice to work around this problem halting deployment?

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,965 questions
{count} votes

Accepted answer
  1. ajkuma 28,036 Reputation points Microsoft Employee Moderator
    2023-05-08T19:02:17.0333333+00:00

    Thanks for posting this question, I understand you have tried multiple things to sort the issue and the setup works locally. While I'm checking on this, you may try the following steps to isolate the issue.

    Review app setting SCM_DO_BUILD_DURING_DEPLOYMENT set to true

    Checkout the steps outlined in this article: Issues with package versions and distributions, building wheels, conflicting dependencies and deprecated packages

    I understand you have leveraged Azure WebApp Linux blessed image, if feasible leverage custom docker Image and see if it helps - checkout this article for more info: Python on Linux App Service and ModuleNotFoundError.

    Kindly let us know, I'll follow-up further.


2 additional answers

Sort by: Most helpful
  1. Adaire 5 Reputation points
    2023-05-17T19:38:40.44+00:00

    As Don Zhu, I had to abandon the oryx containerization and create an Azure VM with my own environment. It’s sad because none of my django package even required the cairo…

    1 person found this answer helpful.

  2. Don Zhu 35 Reputation points
    2023-05-09T16:51:16.6933333+00:00

    Hi Ajkuma, thanks for following up. SCM_DO_BUILD_DURING_DEPLOYMENT is set to true as that causes the oryx build process to occur. If it is turned off, it deploys "successfully" but visiting the site only serves the Application Error :( page from Azure.

    I was able to resolve the issue by building a docker container with the application using the public Python 3.11 image as the base and layering all the OS dependencies required for the application and then pushing to Azure's container registry for continuous deployment. Essentially doing what Oryx does but with enhanced privileges and customizability.

    In my research and in the articles provided, I don't see a way to install required OS packages during the Oryx Build process. For example, apt-get update isn't allowed as a PRE_BUILD_COMMAND. Because the build steps are failing, a container is never built and deployed to allow for post-deploy install scripts to run.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.