Run Python script on boot without logging in; BUT with the installed Python libraries

Hi everyone. I am attempting to configure my Jetson Nano to run a Python script once the device has power. We’re trying to use the Jetson as a vision coprocessor for our team’s robot, and so we don’t want to have login each time we want the script to run.

I’ve followed the thread here and setup a systemd service that runs python3 /usr/local/bin/main.py under the user robot.

However, I’m running into an error. The Python code, when run by the service, is unable to import my Python module pynetworktables. The terminal prints out ModuleNotFoundError: No module named 'networktables' when I check using sudo systemctl status robot When not run by the service, when I simply say python3 /usr/local/bin/main.py, it runs without error.

Here is the beginning of main.py:
import cv2
from networktables import NetworkTables

Oddly, cv2 works fine. It’s successfully getting the OpenCV library.
NetworkTables is not. I installed the library using pip3 install pynetworktables (from these instructions).

So now I guess my question is, how do I fix this issue? Do I need to install the library in a different way? Or use docker or something else like that? I’m guessing that part of the issue is that I’ve installed the library under my regular user, not robot and so it can’t access it. (?)

Any help is appreciated.

Hi,

A possible reason is related to the location of the library installed.

When running the pip3 install pynetworktable, the library is installed to the ${HOME}/.local rather than /usr/lib/.

Would you mind checking if you can access the folder correctly with robot account?
Below is our library location from our environment for your reference:

/home/nvidia/.local/lib/python3.6/site-packages/networktables

Thanks.

Hi, sorry for the late reply.

I attempted to do sudo -u robot ls /home/nvidia/.local and it said ls: cannot open directory '/home/nvidia/.local': Permission denied.

Then I tried accessing this directory with my normal user account and it was perfectly fine.

So robot cannot access the networktables python package, while my normal user can. Any suggestions from here?

Yay! I got it to work by uninstalling pynetworktables and reinstalling under the root user. Thanks for your help in prompting the right questions for me to ask my web browser. :D

I followed the answers from this post: python - How to install a module for all users with pip on linux? - Stack Overflow

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.