I have a python program that imports gopigo. If I run the program under my user it works fine. I need to invoke it from shairport-sync service. when I do that I get the following error:

Jul 27 19:35:56 raspberrypi shairport-sync[489]: Traceback (most recent call last):
Jul 27 19:35:56 raspberrypi shairport-sync[489]: File “/home/pi/Watson/mprobot.py”, line 10, in 
Jul 27 19:35:56 raspberrypi shairport-sync[489]: from gopigo import *
Jul 27 19:35:56 raspberrypi shairport-sync[489]: File “/home/pi/Watson/gopigo.py”, line 60, in 
Jul 27 19:35:56 raspberrypi shairport-sync[489]: bus = smbus.SMBus(1)
Jul 27 19:35:56 raspberrypi shairport-sync[489]: PermissionError: [Errno 13] Permission denied

How do i give the shairport-sync service permission? Or is there another solution?

  • Welcome, I've edited your post to correct the module name in your typing to match that of the error messed. Please be careful over such things as it can end up with wrong help. It's also worth while to explain what the program is trying to do, what it is written in (inc version) and what Pi and OS version you are using :-) Links to any instructions you are following and where the libraries came from may help. one a minor note - I'm baffled / nosey on why a robot control program would need to play via airplay?!?
    – user115418
    Jul 29, 2020 at 3:11
  • The userid running the smbus code needs to be in the I2C group to be able to access the I2C devices. sudo usermod -a -G i2c shairportuseridgoeshere
    – Dougie
    Jul 29, 2020 at 11:26
  • I'm making the gopigo voice controlled. I couldn't use the usb mic since the motor noise drowns out the commands. I use airplay to send commands from my iphone to shairport on the rpi which then writes it to a file for processing.. I have it all working but just trying to clean up some code. If you want to know more let me know.
    – Hankp
    Jul 30, 2020 at 11:13

1 Answer 1


First this to do if find out which user the program is running under.

Simplest way is to use

ps aux | less

Use the cursor keys to scroll up and down the list and once the job has been found use 'q' to return to the command line. Note the user is in the first column.

You then need to give that user permission to use the GPIO pins by becoming a member of one or more of three groups:

gpio i2c spi

Normally, I give access to all three groups for background users as I do not restrict them to interface types as, long term I may change what they do. This is bad security practise as users should ONLY have the MINIMUM rights to do the job needed - please do not follow my bad habits...

Issue the following command to add the group to the user:

usermod -a -G group user

Replace group with gpio, i2c or spi as needed (remember minimum access = good practice). Replace user with the name from the ps output.

Do not use lowercase G as this changes the primary group the user belongs to and all files etc will be owned by that group and not by the user.

You can then restart the job and check if that's fixed it. Note it's best to make sure all jobs for that user are ended while changing groups - again bad practise is to reboot the pi as one day you will do it on the wrong machine out of habit...

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.