Question about directories and dependencies

I am developing a simple project in Python that opens my computer’s camera using OpenCV. My main goal is to understand how to build a snap and then move on to more complex projects. My main question is about dependencies, I have read and reread many tutorials but it is still not clear to me. My snap contains 2 parts. The first is the camera.py source file that imports the cv2 module and the second is opencv that contains the python3-opencv stage-package and gtk related dependencies (libcanberra-gtk-module, libcanberra-gtk3-module, libcanberra-gtk0, libcanberra-gtk3-0). Despite this the build process complains about missing dependencies (libpsm_infinipath.so.1) and returns a huge amount of warnings about unused dependencies. Despite this the snap is created and executed, but with the warning “Failed to load module canberra-gtk-module”. My question is, what is the ideal snapcraft.yaml for this application and how can I properly manage the dependencies so that they are installed and localized, without getting garbage or broken links?

camera.py

#!/usr/bin/python3
import cv2 as cv

cam_addr = 0

cap = cv.VideoCapture(cam_addr)

if not cap.isOpened():
    print("Cannot open camera")
    exit()

while True:

    ret, frame = cap.read()

    if not ret:
        print("Can't receive frame (stream end?). Exiting ...")
        break

    cv.imshow('frame', frame)

    if cv.waitKey(1) == ord('q'):
        break

cap.release()
cv.destroyAllWindows()

snapcraft.yaml

name: coutos
base: core22
version: '1.0'
summary: acessar camera do notebook
description: gtk and organize

grade: devel
confinement: devmode


apps:
  coutos:
    command: bin/camera.py
    plugs:
      - camera
    environment:
      PYTHONPATH: $SNAP/usr/lib/python3/site-packages:$SNAP/usr/lib/python3/dist-packages:$PYTHONPATH

parts:
  source:
    plugin: dump
    source: src/
    organize:
      camera.py: bin/camera.py

  opencv:
    plugin: python
    source: .
    stage-packages:
      - python3-opencv
      - libcanberra-gtk-module
      - libcanberra-gtk3-module
      - libcanberra-gtk0
      - libcanberra-gtk3-0
    organize:
      usr/lib/*-linux-gnu/blas/*: usr/lib/
      usr/lib/*-linux-gnu/lapack/*: usr/lib/

You probably should use the gnome extension which will handle most of the Gtk and graphical application configurations for you if your application depends on it.

You should also switch to strict confinement and test whether your application can function properly under it.

Happy snapcrafting!