After trying every possible solution online I am posting this question. I have a python script that runs on boot with the help of systemd. Everything worked fine till I installed a fresh raspian buster. Now I am able to run the python program via both systemd and through Thonny Editor. But the difference is that systemd doesn't give any audio output while the editor does. I tried to run my python script via terminal and the audio was playing without any issues.

Now please note that I have another raspberry pi which is still running the older version of the OS with the same systemd configuration and everything works fine in it. Now I could have easily cloned that sd card and used it but that sd card is 16 GB and I want to migrate to a 32 GB sd card(I tried cloning, pi didn't boot up)

This is the systemd service file

Description=My Service

ExecStart=/usr/bin/python3 -u Main.py
WorkingDirectory= /home/pi/xyz

WantedBy = default.target

Systemd runs the python file without any errors but with no audio output. Please help me out.

  • What does the script do? Does it endless play a sound in the background? Do you use pulseaudio?
    – Ingo
    Jan 10, 2021 at 18:44
  • @Ingo The script plays a welcome sound when started and then will play sound whenever the push buttons are clicked. Very basic stuff. Jan 11, 2021 at 2:26
  • 1
    I am having the same problem exactly. Was a solution ever found? I can get it to work via a .desktop file, but I'd really like to use functionality of systemd. May 19, 2021 at 20:16
  • @PeterWiley No solution was found. I had to shift to the older version of Raspian OS. Because after updating this problem started for me. May 20, 2021 at 8:10
  • 1
    I know, I'm the one who submitted the answer. May 21, 2021 at 16:03

2 Answers 2


The answer to this issue can be found here:


The solution presented worked for me to get sound while running a python program from system.

What one has to do is to add defaults to the asound.conf file at /etc/asound.conf. I did sudo nano on file and found nothing in it, so I added

   defaults.pcm.card 1
   defaults.pcm.card 1

Why "1"? It's the number given when one does

    pi@xxxx:~ $ cat /proc/asound/cards
    0 [b1             ]: bcm2835_hdmi - bcm2835 HDMI 1
                  bcm2835 HDMI 1
    1 [Headphones     ]: bcm2835_headphonbcm2835 Headphones - bcm2835 Headphones
                  bcm2835 Headphones

In my case I wanted sound out of the headphone jack.

  • Thank you so much for the answer. May 21, 2021 at 8:17

This service file worked for me... note how it starts after sound.target

[Unit] Description=FireHouse Game After=sound.target

[Service] Type=simple Environment="DISPLAY=:0" Environment="XAUTHORITY=/home/pi/.Xauthority" ExecStart=/usr/bin/python3 /home/pi/FireGame/fire_game.py Restart=on-abort KillMode=process SendSIGHUP=nos

[Install] WantedBy=graphical.target

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.