Search code examples
pythonembeddedsystemdsystemctlnvidia-jetson-nano

Runnig a python script using systemd and service file on the jetson nano


i'm trying to set the right parameter to run up a python script when the jetson nano is powered up. I'm facing a problem that the service file doesn't want to recognize the library that was installed using pip. If the code was compiled from the command line it works fine without facing any problem but with the systemd support i get this error: here the first image(upload://k2pWgcIRAB7N2OzLrascOEi1HrI.jpeg)

second image

The service file looks like the following figure: service file

i'll be really gratefull if someone can help me.


Solution

  • You have a few options, but essentially what you need to do is make sure the installed packages are available to python when run as the configured user (root by default).

    Next, since you've split your script into multiple files, you need to make sure those files are in locations known to python (or instruct python to look in additional directories).

    The following configuration should help, assuming running the script as the znvidia user from within /home/znvidia is what you had working.

    [Unit]
    Description="Some useful description"
    
    [Service]
    User=znvidia  # Or leave out for root
    WorkingDirectory=/home/znvidia/Desktop
    ExecStart=/usr/bin/python3.6 /home/znvidia/Desktop/Drowsiness_detection.py
    
    [Install]
    WantedBy=multi-user.target