0

After searching for some time- I can;t find the reason that my python3 code won't execute during boot. I'm using Rpi Zero, using StrechLite OS. Code run OK when is executed from command line.

crontab contains:

@reboot /usr/bin/pigpiod
@reboot /usr/bin/python3 /home/guy/Documents/github/Rpi/SmartHome/tst.py &                       

try 1:

I've created a bash file (containing echo "guy" >>log.log )to see if cron job is running OK- and redirected its output to a text file. All went well.

try 2:

bash file was edited to run ( python3 /home/guy/Documents/github/Rpi/SmartHome/tst.py ) , but it failed.

try 3:

a simple python code was written, 123.py containing a single line: print("GUY") to be executed as : @reboot /usr/bin/python3 /home/guy/Documents/github/Rpi/SmartHome/123.py >>log.txt in order to check if something is python code during boot time, make it fail- but still python code is not executed during boot.

What is done wrong in order to run a python script this way?

7
  • What's in your python script? That might be failing due to path issues.
    – Brick
    Mar 12, 2018 at 22:34
  • crontab outputs information to /var/log/cron.log - anything there to indicate what the failure is? Mar 12, 2018 at 23:00
  • The pigpio daemon needs to be run as root. Best to put the first line in the root crontab. Also the daemon may take a second or so to launch. Perhaps you need a delay before launching your script if it is using pigpio.
    – joan
    Mar 13, 2018 at 2:18
  • @Brick path was checked and is correct
    – guyd
    Mar 13, 2018 at 3:45
  • @joan pig poof is running ok. The problem is execution of second line
    – guyd
    Mar 13, 2018 at 3:47

1 Answer 1

0

After trying solving it with creation of daemon service (systemctl), which yield same unwanted result - I found the reason why:

using in crontab or daemon service - couldn't get $PYTHONPATH in time ( or boot sequence ) to find path needed to run a certain module I use.

so I added to my python code: sys.path.append('/home/guy/Documents/github/Rpi/GPIO_Projects/lcd') -in oder to find that particular module handling LCD display.

BTW- the above path is part of $PYTHONPATH, which probaby update after logging in, or running python IDE, but not when trying to automatically execute a code after OS boots up ( without logging in ).

Guy

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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