bbd 666
bbd 666

Reputation: 13

run a python script in a service : RuntimeError: No access to /dev/mem/

here is my python script I want to run @reboot. For that I built a service using systemd :

import vlc
import time
import board
from time import strftime
from PIL import Image, ImageDraw, ImageFont
import configparser
import RPi.GPIO as GPIO
import sys
from time import sleep
import digitalio
import adafruit_ssd1306
import evdev
from datetime import datetime
volume_ini=100
time_var=""
date_var=""
row_list=[23,24,25]
col_list=[4,5,6]
GPIO.setmode(GPIO.BCM)
for pin in row_list:
   GPIO.setup(pin,GPIO.OUT)

Here is my service that i linked to a custom.target to execute at the end of the boot:

[unit]
After=multi-user.target

[Service]
type=oneshot
User=pierre
Execstart= /usr/bin/python /home/pierre/Documents/toto.py

[Install]
WantedBy=custom.target

when I rebot it fails with the error :

GPIO.setup(pin,GPIO.OUT)
RuntimeError: No access to /dev/mem/ Try running as root !

when I set User=root it fails due to paths :

import board . lib board not found

I also tried :

sudo usermod -aG kmem pierre

of course when i run my script in the command prompt it works fine in user mode (not as root for same reason of paths).

Upvotes: 0

Views: 25

Answers (0)

Related Questions