添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接

Hello there, I am developing a simple application in python using pygame which plays sound files. here is my snapcraft.yaml

name: white-canary  # Replace with your application's name
base: core20             # The base snap is the execution environment
version: '0.8'                  # Version of your application
summary: A brief description of your application
description: A detailed description of your application.
grade: devel                    # Must be 'stable' to release into candidate/stable channels
confinement: strict             # Use 'strict' to enforce security and isolation
parts:
  white-canary:                     # This part name can be anything
    # Specifies where to fetch your source code from
    source: .                   # Use '.' to designate that the source code is in the same directory as the snapcraft.yaml
    plugin: python              # This plugin will use pip to install your Python packages
    python-packages:
      - flask                   # Ensure all your Flask dependencies are listed
      - pygame
      - requests
      - wheel
    stage-packages:             # List the Ubuntu packages needed at runtime
      - libasound2
      - alsa-utils
      - libasound2-plugins
      - libsdl1.2debian
      - libsdl-mixer1.2
      - libportaudio2
      - ffmpeg
      - libglu1-mesa
      - freeglut3
apps:
  white-canary:
    command: bin/hello     # Adjust to how you would run your app
    plugs:
      - network                 # Allows networking, e.g., access to the network
      - network-bind            # Allows binding to network ports
      - home                    # Grants access to non-hidden files in the user's home directory
      - audio-playback          # Allows playback of audio
      - audio-record            # Use if your application needs recording capabilities

The snap is building successfully, but when I run the app it fails with this error message

pygame 2.5.2 (SDL 2.28.2, Python 3.8.10)
Hello from the pygame community. https://www.pygame.org/contribute.html
ALSA lib conf.c:4120:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib conf.c:4120:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
ALSA lib conf.c:4120:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib conf.c:4120:(snd_config_update_r) Cannot access file /usr/share/alsa/alsa.conf
ALSA lib pcm.c:2642:(snd_pcm_open_noupdate) Unknown PCM default
Traceback (most recent call last):
  File "/snap/white-canary/x11/bin/hello", line 5, in <module>
    from src.app import main
  File "/snap/white-canary/x11/lib/python3.8/site-packages/src/app.py", line 12, in <module>
    pygame.mixer.init()
pygame.error: ALSA: Couldn't open audio device: No such file or directory
  • I tired connecting my snap to audio-playback, alsa manually, it didnt work
  • Also I noticed this warning message running the snapcraft command
  • Copying needed symlink target '/usr/bin/python3.8' from host to satisfy '/root/parts/white-canary/install/bin/python3'.
    'lib/systemd/system/alsa-utils.service' will be a dangling symlink
    Updating pull step for white-canary (source changed)
    + snapcraftctl pull
    'lib/systemd/system/alsa-utils.service' will be a dangling symlink
    Updating build step for white-canary ('pull' step changed)
    

    Im running this on Intel PC 64 bit ubuntu desktop, when I normally run the python app, its working fine without any issues. Please help me with this, I wanted to do more with the snapcraft :slight_smile: but this is blocking me. Thanks in Advance.

    @popey , this variable allows to specify the audio driver that SDL (the library used by pygame to manage audio) should use.

    By setting this environment variable, we might be able to work around some ALSA issues by telling SDL to use a different audio driver.

    Hmm ! @popey :blush:.

    The goal in itself is that it works.

    Afterwards we can vary according to our preferences.

    No one is omniscient, I am here mainly to learn (in theory and in practice) :beginner:.

    Right, but I keep seeing what looks like either chat-gpt or random googling in responses to technical questions from you.

    This leads people down the wrong path. If you have a solid answer which helps to resolve the question, then by all means answer the question. But if you pluck a random environment variable to select audio technology from the previous century, when we’ve all moved on from OSS through ALSA to Pulse and now Pipewire, the user is going to have a bad day. So please, can we try and post more researched and authoritative answers, not wild guesses?

    @popey ! One of the most desired wishes of a humain being aspiring to rational purity is to be perpetually in power.

    As a French-speaking person, if I had thought that my words and writings should accurately reflect the depths of my thoughts and my soul, I would never express myself or write in English. However, I persevere in writing and speaking in English, because I am firmly convinced that it greatly contributes to my personal enrichment.

    Not all answers may come from documented official sources or anything of that nature.
    Moreover, there have never been any solutions that have become state-proven without rigorous testing. And yes, I sometimes use all the tools available that have proven their worth before making certain proposals or suggestions, and I am very happy about that.

    Once again, I am mainly here to learn.

    It often happens that we ignore our own initial learning here and there, especially when certain areas seem surprisingly familiar and easily masterable.

    Hi @baldeuniversel thanks for the response,

    I tried this along with dsp, I got this, if I ignore the dsp, Im facing the original issue, no difference.

    pygame.error: dsp: No such audio device
    
    CVE-2020-27348: A potentially empty LD_LIBRARY_PATH has been set for environment in 'white-canary'. The current working directory will be added to the library path if empty. This can cause unexpected libraries to be loaded.
    

    Also got the above one while snapcraft

    Hi @popey, thank you for the response

    I followed the solution posted by James, I added the alsa-pulseaudio to the parts and layout definition, following the github repo he posted.

    this time it seems to find the alsa.conf but something else came up now,

    Hello from the pygame community. https://www.pygame.org/contribute.html
    ALSA lib control.c:1379:(snd_ctl_open_noupdate) Invalid CTL hw:0
    ALSA lib dlmisc.c:283:(snd_dlobj_cache_get0) Cannot open shared library /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_pulse.so ((null): libpulsecommon-13.99.so: cannot open shared object file: No such file or directory)
    ALSA lib control.c:1379:(snd_ctl_open_noupdate) Invalid CTL hw:0
    ALSA lib control.c:1379:(snd_ctl_open_noupdate) Invalid CTL hw:0
    ALSA lib dlmisc.c:283:(snd_dlobj_cache_get0) Cannot open shared library /usr/lib/x86_64-linux-gnu/alsa-lib/libasound_module_pcm_pulse.so ((null): libpulsecommon-13.99.so: cannot open shared object file: No such file or directory)
    ALSA lib control.c:1379:(snd_ctl_open_noupdate) Invalid CTL hw:0
    Traceback (most recent call last):
      File "/snap/white-canary/x20/bin/hello", line 5, in <module>
        from src.app import main
      File "/snap/white-canary/x20/lib/python3.8/site-packages/src/app.py", line 12, in <module>
        pygame.mixer.init()
    pygame.error: ALSA: Couldn't open audio device: No such device or address
                  

    After adding libpulse0 im still getting the same error. I am sorry if im wrong, but I thought gnome is related to UI, and I dont have any UI related stuff in my app. Regardless of that I added that too, and I got a new error.

    RROR: Could not install packages due to an EnvironmentError: [Errno 30] Read-only file system: '__init__.py'
    Failed to build 'white-canary'.
    Recommended resolution:
    Check the build logs and ensure the part's configuration and sources are correct.
    

    without extension and adding libpulse0, Im getting the previous error, I posted.