Python Cairo not found

Hi, I am learning how to create snap packages and today I was trying to create one for a git repository. The .yaml file is as follows:

name: mysnap
base: core18 # the base snap is the execution environment for this snap
version: '0.1' # just for humans, typically '1.2+git' or '1.3.2'
summary: mysnap
description: |
grade: devel # must be 'stable' to release into candidate/stable channels
confinement: devmode # use 'strict' once you have the right plugs and slots

    # See 'snapcraft plugins'
    plugin: python
    python-version: python3
    source: ./
      - python3-dev
      - python3-numpy
      - subversion
      - ffmpeg
      - libsdl1.2-dev
      - libsdl-image1.2-dev
      - libsdl-mixer1.2-dev
      - libsdl-ttf2.0-dev
      - libavcodec-dev
      - libavformat-dev
      - libportmidi-dev
      - libsmpeg-dev
      - libswscale-dev
      - gstreamer1.0-plugins-base
      - gstreamer1.0-plugins-bad
      - gstreamer1.0-plugins-ugly
      - gstreamer1.0-plugins-good
      - libcairo2-dev
      - libgirepository1.0-dev
      - ttf-mscorefonts-installer
      - libopenjp2-7
      - python3-venv
      - python3-gst-1.0
      - gstreamer1.0-tools
      - libjpeg-dev
      - libxslt1-dev
      - gstreamer1.0-libav
      - python3-cairo
      - libcairo-gobject2
      - libfontconfig1
      - libfreetype6
      - libgirepository-1.0-1
      - libpixman-1-0
      - libpng16-16
      - libx11-6
      - libxau6
      - libxcb-render0
      - libxcb-shm0
      - libxcb1
      - libxdmcp6
      - libxext6
      - libxrender1
      - python3-gi
      - gobject-introspection
      - gir1.2-gtk-3.0

    command: bin/runner

The problem is that when I try to run the package command it does not find the cairo library, and I have already tried installing libcairo2, libcairo2-dev and python3-cairo and none of these work, it always send moduleNotFoundError: No module named 'cairo'

Does anyone know what I am doing wrong and how I could fix it?

Have you tried specifying python3-cairo as a stage package? I noticed that you are installing it for the build packages, but not the stage packages. Build packages are only around for when you are building the snap. They do not exist in the final package. Stage packages stick around since they are need for runtime.

Let me know how installing python3-cairo in the stage packages goes. If it does not work, you may be able to get around the issue by installing cairo via pip.

1 Like

Thanks! It worked :smile: , but I’d still like to know how to install packages inside the snap using pip

You can list Python packages to install using python-packages, or requirement files using python-requirements (or only requirements if you’re using core18 or core20). More details in the documentation.

1 Like