0

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.

Zac Boussaid
  • 35
  • 1
  • 8
  • Where did you install the package to? Systemd will run the executable as root by default, so make sure the package is available when running as root or run the service as your own user. (I'm not saying you should install as root, just that it needs to be installed to a location where python will look for packages when run as root. `(sudo) python3 -m site`) – frippe Oct 07 '21 at 13:27
  • i installed the playsound library for example in this location: ./.local/lib/python3.6/site-packages @frippe – Zac Boussaid Oct 07 '21 at 13:52
  • That's a relative path. I take it you're referring to ~/.local/lib/....? Did you try configuring the service to run as the user that installed the package? – frippe Oct 07 '21 at 14:00
  • Yes. I really don't know how. could you tell me how to configure it correctly – Zac Boussaid Oct 07 '21 at 14:03
  • That's a trivial thing to google. Anyway, `User=` under `[Service]` – frippe Oct 07 '21 at 14:14
  • Also available under man pages for `systemd.directives` and `systemd.exec` – frippe Oct 07 '21 at 14:21
  • hey @frippe the first idea was really great. I installed the packages as root and i i have successfully solve the problem. But know my system doesn't want to import the other files like the sound file which was called from my Python code – Zac Boussaid Oct 08 '21 at 06:21
  • Are you referring to the files by absolute path? – frippe Oct 08 '21 at 06:27
  • I'm referring to my files like this: [enter image description here][4] [enter image description here][5][4]: https://i.stack.imgur.com/HODb3.jpg [5]: https://i.stack.imgur.com/4dIFp.jpg – Zac Boussaid Oct 08 '21 at 07:17
  • I meant the path to the sound file used in your script – frippe Oct 08 '21 at 07:35
  • Nope i got it i defined the absolute path and it worked. Thank you very much. Now i'm getting some problem with the import from classes that i made by myself – Zac Boussaid Oct 08 '21 at 07:46
  • i Know how python import packages but the question here how does systemd import packages. Thank you again for help i'll keep searching i give you all updates – Zac Boussaid Oct 08 '21 at 08:14
  • Either I'm not following what you mean or you're confused about the importing here. It's not systemd importing the packages, it's python. The directories where python will look for packages depend on how a script is invoked. You can't just import packages in random locations on your computer, they either need to be put in specific locations or python needs to be explicitly configured to look for imports in additional directories. – frippe Oct 08 '21 at 08:21

1 Answers1

0

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
frippe
  • 1,329
  • 1
  • 8
  • 15