Problem deploying with pycairo

Hi,

I’m having a problem with deploying an app onto an azure web-app service because the deployment action is unable to find the pycario packages

My action is as follows:

name: Build and deploy Python app to Azure Web App - mep-configurator

on:
  push:
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2

      - name: Set up Python version
        uses: actions/setup-python@v1
        with:
          python-version: '3.10'

      - name: Create and start virtual environment
        run: |
          sudo apt-get update
          sudo apt-get install -y libcairo2-dev libjpeg-dev libgif-dev
          python -m venv venv
          source venv/bin/activate
      
      - name: Install dependencies
        run: pip install -r requirements.txt
        
      # Optional: Add step to run tests here (PyTest, Django test suites, etc.)
      
      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !venv/
  deploy:
    runs-on: ubuntu-latest
    needs: build
    environment:
      name: 'Production'
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: python-app
          path: .
          
      - name: 'Deploy to Azure Web App'
        uses: azure/webapps-deploy@v2
        id: deploy-to-webapp
        with:
          app-name: 'mep-configurator'
          slot-name: 'Production'
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE_D66086F2554D4C2F9BE23A1323FCFE87 }}

The error I’m getting is:

Building wheels for collected packages: pycairo\n[00:43:51+0000]   Building wheel for pycairo 
(pyproject.toml): started\n[00:43:53+0000]   Building wheel for pycairo (pyproject.toml): finished with 
status 'error'\n  error: subprocess-exited-with-error\n  \n  × Building wheel for pycairo (pyproject.toml) 
did not run successfully.\n  │ exit code: 1\n  ╰─> [15 lines of output]\n      running bdist_wheel\n      
running build\n      running build_py\n      creating build\n      creating build/lib.linux-x86_64-cpython-
310\n      creating build/lib.linux-x86_64-cpython-310/cairo\n      copying cairo/__init__.py -> 
build/lib.linux-x86_64-cpython-310/cairo\n      copying cairo/__init__.pyi -> build/lib.linux-x86_64-
cpython-310/cairo\n      copying cairo/py.typed -> build/lib.linux-x86_64-cpython-310/cairo\n      running 
build_ext\n      Package cairo was not found in the pkg-config search path.\n      Perhaps you should 
add the directory containing `cairo.pc'\n      to the PKG_CONFIG_PATH environment variable\n      No 
package 'cairo' found\n      Command '['pkg-config', '--print-errors', '--exists', 'cairo >= 1.15.10']' 
returned non-zero exit status 1.\n      [end of output]\n  \n  note: This error originates from a 
subprocess, and is likely not a problem with pip.\n  ERROR: Failed building wheel for 
pycairo\n[00:43:53+0000] Failed to build pycairo\nERROR: Could not build wheels for pycairo, which is 
required to install pyproject.toml-based projects\n\n[notice] A new release of pip available: 22.2.2 -> 
23.1.2\n[notice] To update, run: pip install --upgrade pip  

Any help would be welcomed. Thanks

What about following the documentation?

https://pycairo.readthedocs.io/en/latest/getting_started.html

I would try this:

sudo apt-get install -y build-essential libcairo2-dev pkg-config python3-dev
1 Like

Hey @Franky1
The error occurs following what is in the documentation.

    steps:
      - uses: actions/checkout@v2

      - name: Set up Python version
        uses: actions/setup-python@v1
        with:
          python-version: '3.10'

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      
      - name: Install dependencies
        run: |
          sudo apt-get install -y build-essential libcairo2-dev pkg-config python3-dev
          pip install -r requirements.txt

      - name: Upload artifact for deployment jobs
        uses: actions/upload-artifact@v2
        with:
          name: python-app
          path: |
            . 
            !venv/

This is what is into the requirements.txt
numpy==1.23.3
pandas==1.5.0
streamlit==1.12.0
pycairo==1.23.0;

Then probably some more apt packages are missing.
Just google for the error message and you will find some more hints.
Maybe libgirepository1.0-dev is missing.
I cannot reproduce your error, since i don’t know the state of this ubuntu-latest container after the setup-python action.

I have been googling for a while without any successful results.

I could use another version of Ubuntu if you can reproduce the error.

As I said before, I cannot reproduce the error. The docker images I tested did not show this error message. I don’t have a local environment where I can provoke this error, so I can’t help.
It looks like Github Actions, what I notice is that the action is outdated, I would use the latest actions/setup-python@v4 action.

Brilliant work, thanks for your help Franky

Thanks, @Franky1
I think the problem relies on using the standard GitHub action to push the app to the Azure static web app.

We will try to move the development using a docker container which will be pushed to the Azure container registry.
Said that it would be nice to understand if it is possible to achieve the same using the standard GitHub action.
Cheers.

Here are some updates.

After some tests, this doesn’t fail.

      - name: Install system packages
        run: |
          sudo apt-get update
          sudo apt-get install libpango1.0-0 libcairo2 libgtk-3-dev libpq-dev libffi-dev
          sudo apt install libcairo2-dev pkg-config python3-dev
          ldconfig -p | grep cairo

      - name: Create and start virtual environment
        run: |
          python -m venv venv
          source venv/bin/activate
      
      - name: Install dependencies
        run: |
          pip3 install pycairo
          pip3 install -r requirements.txt

but when the app opens, this is the error.

File “/tmp/8db4af7125a58fc/antenv/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py”, line 556, in _run_script
exec(code, module.dict)

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.