I am trying to run a python script that uses the RPi Camera on boot from /etc/rc.local. This is the command I need to run:

python ~/Documents/camera/camera.py --conf ~/Documents/camera/conf.json This is what my rc.local file looks:

#!/bin/sh -e
# rc.local
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
# In order to enable or disable this script just change the execution
# bits.
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
python ~/Documents/camera/camera.py --conf ~/Documents/camera/conf.json &
exit 0

I also tried putting this in my rc.local file to find the error, but the log remained empty. python ~/Documents/camera/camera.py --conf ~/Documents/camera/conf.json > ~/Documents/camera/logfile.log

I know for sure that the python command works because I tried running it from the terminal. The python code I am using is from this tutorial but modified,

3 Answers 3


It is always best to give the full path to commands and data files when not running programs as your user.

In this case rc.local is running as the root user.

The Python version you expect to use may or may not be in the root users path.

The ~ operator will refer to root's home directory (/root) which probably is not where the Documents directory resides.

Replace python with the full root to the Python version you want to use (enter the command which python to check). Replace ~ with (I guess) /home/pi.

  • Replacing the ~ fixed my problem. Changing python to its full root worked but it worked if I left it alone as well. Thanks!
    – shurup
    Nov 26, 2017 at 21:43

One of the reasons, this usually occurs is because one or more of your library/modules are not globally installed. So it's not accessible by admin(or root in linux).

Solution: So you can install it for all users, or alternatively run the python program as specific user instead of admin (or root).

In he case of Linux:

sudo -H -u user /absolute/path/of/python/executable /absolute/path/to/python/program

or more specific:

sudo -H -u pi /usr/bin/python3 /home/pi/sample.py

I had similar issue it turned out be that the supporting libraries that you used were installed as a different user (in my case pi user), which root did not "see" or were in root's path. A simple test went to run them as sudo (which simulates running as root) i got this error.

sudo /usr/bin/python /home/pi/subled.py

caused this error

Traceback (most recent call last):
  File "/home/pi/subled.py", line 16, in <module>
   import schedule   # install with:   pip install schedule
   ImportError: No module named schedule

So I simply did a sudo pip install schedule

And that took care or my issue

Also be sure to check that user root has execute permissions on the python script your planning on using

  • This is the better answer as it gives more options on the problem. Lack of the packages for root is one of the common problem and here is the way to track everything down Dec 3, 2019 at 16:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.