I have a python script which uses motion sensor and camera. It captures an image and stores to the same folder where the script resides. No errors when I run it in bash. But I created this service for systemd to make it run on start up:

Description=Run office intrusion detection

ExecStart=/usr/bin/python3 -u /home/myuser/Documents/prog/pricam.py


and when it runs I see this error:

>>Traceback (most recent call last):
File "/home/alvipeo/Documents/progs/pricam.py", line 24, in <module>
File "/usr/lib/python3/dist-packages/picamera/camera.py", line 1418, in capture
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 1126, in start
super(PiCookedOneImageEncoder, self).start(output)
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 375, in start
File "/usr/lib/python3/dist-packages/picamera/encoders.py", line 331, in _open_outpu
t self.outputs[key] = mo.open_stream(output)
File "/usr/lib/python3/dist-packages/picamera/mmalobj.py", line 344, in open_stream
stream = io.open(stream, 'wb' if output else 'rb', buffering)
PermissionError: [Errno 13] Permission denied: '/home/myuser/Documents/progs/pi

I'm not a good linux user, so could you please tell me what's wrong here?


It appears in your system daemon configuration you have "User=pi" while the path to the image is clearly located in the "myuser" user directories. So, likely the permissions are such that user "pi" can not alter user "myuser"'s files.

  • I tries myuser, but that presents another problem with GPIO and camera permissions. so how can I grant pi permission to write files to myuser folders? – Alex Bee Jun 6 '18 at 16:08
  • If security is not a concern, you can open up the permissions of the directory /home/myuser/Documents/progs (chmod 777 /home/myuser/Documents/progs) so that any user could write to it. However, I would think the easier option is to store the images in a directory owned by user "pi" instead of user "myuser". – st2000 Jun 7 '18 at 3:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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