I was making a battery notifier script for my raspberry pi3. The script is executing when I do/usr/bin/python /home/pi/Documents/shutdown.pyand showing the popup notifications. However the service is not executing it or not showing the notification. I can see the python process if I do sudo systemctl status battery-notifier.service.battery-notifer.service[Unit]Description=Battery Notifier[Service]Type=simpleWorkingDirectory=/home/pi/DocumentsExecStart=/usr/bin/python /home/pi/Documents/shutdown.py[Install]WantedBy=multi-user.targetshutdown.pyimport raspiupshatimport statisticsimport subprocessfrom time import sleepraspiupshat.init()while(True):    voltagesList = []    sleep(0.5)    currentVoltage = raspiupshat.getv()    voltagesList.append(currentVoltage)    medianVoltage = statistics.median(voltagesList)    if(medianVoltage>4):        subprocess.Popen([notify-send,Battery Full!])This is the status of the service when I do sudo systemctl status battery-notifier.service: battery-notifier.service - Battery Notifier   Loaded: loaded (/lib/systemd/system/battery-notifier.service; enabled)   Active: active (running) since Sat 2017-07-15 04:05:18 UTC; 48min ago Main PID: 28384 (python)   CGroup: /system.slice/battery-notifier.service           28384 /usr/bin/python /home/pi/Documents/shutdown.pyJul 15 04:05:18 raspberrypi systemd[1]: Started Battery Notifier.
systemd service not executing the python script
systemd;python;raspberry pi;libnotify;notify send
Edited to add: Your program tries to access the graphical desktop of a user (pi), however, it is itself executed by systemd. That is, it will run as root per default and not as the user pi. Moreover, there might not even be a graphical desktop yet at the time this is started. Therefore, you could go several paths:Start the program not via systemd, but when the logged in user starts the graphical desktop. Therefore, you need to put the program start into the file ~/.xinitrc or ~/.xprofile. See the Arch Wiki on AutostartAdd a line User=pi to your systemd service. This is the solution you mentioned in the comment to your original postsystemd can be configure to be executed in a user-mode (as opposed to system mode) when the user logs in. You could let your service be started by that way. See the Arch Wiki on systemd/UserOriginal answer:See this SO question. There is an env= parameter in the subprocess.Popen(.) function which can be used. Alternatively, you could use the feature of sh that if you assign a variable immediately before a call, that variable is set (only) for that call:myvar=world# cannot use echo $myvar, because $myvar would be substituted before echo is launchedmyvar=hello declare -x myvar echo $myvargivesdeclare -x myvar=helloworldLink to corresponding chapter in POSIX specSo for you: subprocess.call(DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-goOEk5dZcK,guid=9c1f14175e6be0992b16e5155969b46c notify-send 'Battery full!',shell=True)The call you mentioned in the comment to your question does not work because it leads to the following processsubprocess.Popen('export DBUS_SESSION_BUS_ADRESS=..., shell = True)Launch a shell Set the environment variable DBUS_SESSION_BUS_ADRESS=... for this shelland all sub-shells (that's what export does).What it does NOT: Set the variable for all shells there are on the machine!Close the shell. Now the value of DBUS_SESSION_BUS_ADRESS is lost again.subprocess.Popen(['notify-send',...], shell=True)Launch a shellThe export call of the previous shell has no power here because these two shells are completely unrelatedLaunch notify-send as in your original questionSo the setting of the environment variable has no effect here.