I have a raspberry pi 4, EDIT: using python3.7, with raspbian OS Devian 10 Buster and I am trying to run a script afeterboot for people counting, it uses a virtual env, after reading various post this is the bash on_reboot.sh I am using:
#!/bin/bash
sleep 3
echo export DISPLAY=:0
source /home/pi/.virtualenvs/cv/bin/activate
python /usr/pi_reboot/contador_final_v2.py -p /usr/pi_reboot/mobilenet_ssd/MobileNetSSD_deploy.prototxt -m /$
After aplying chmod +x
I try it and runs perfect, I am using crontab -e
for running after boot:
@reboot bash /usr/pi_reboot/on_reboot.sh >>/tmp/log 2>&1
In the log I got the next message: Gtk-WARNING date : cannot open display:
Yes, the script uses a window to show the video, what could I do to fix it? I have put the export DISPLAY=:0
in the bash, but doesn't work. Is crontab the best way to do it? also tried it in rc.local but again, no success.
Edit1: The log I get everytime I turn on the Raspberry is:
export DISPLAY=:0
Unable to init server: No se pudo conectar: Conexión rehusada
(Frame:886): Gtk-WARNING **: 15:17:23.228: cannot open display:
Edit2:
Applied Ingo alternative, got this
nov 23 18:08:28 raspberrypi rc.local[476]: File "/usr/pi_reboot/pyimagesearch/centroidtracker.py", line 2, in <module>
nov 23 18:08:28 raspberrypi rc.local[476]: from scipy.spatial import distance as dist
nov 23 18:08:28 raspberrypi rc.local[476]: ImportError: No module named scipy.spatial
nov 23 18:08:28 raspberrypi sudo[483]: pam_unix(sudo:session): session closed for user root
nov 23 18:08:30 raspberrypi systemd[1]: systemd-rfkill.service: Succeeded.
nov 23 18:08:32 raspberrypi dhcpcd[456]: wlan0: leased 192.168.1.18 for 86400 seconds
nov 23 18:08:32 raspberrypi avahi-daemon[385]: Joining mDNS multicast group on interface wlan0.IPv4 with address 192.168.1.18.
nov 23 18:08:32 raspberrypi avahi-daemon[385]: New relevant interface wlan0.IPv4 for mDNS.
nov 23 18:08:32 raspberrypi avahi-daemon[385]: Registering new address record for 192.168.1.18 on wlan0.IPv4.
nov 23 18:08:32 raspberrypi dhcpcd[456]: wlan0: adding route to 192.168.1.0/24
nov 23 18:08:32 raspberrypi dhcpcd[456]: wlan0: adding default route via 192.168.1.1
nov 23 18:08:36 raspberrypi CRON[377]: pam_unix(cron:session): session closed for user pi
nov 23 18:08:39 raspberrypi dhcpcd[456]: wlan0: no IPv6 Routers available
nov 23 18:08:39 raspberrypi vncserver-x11[489]: HostedRendezvous: Connection to [EaNEhY-gjcSg-KAyMLF] is from user "<my_email
nov 23 18:08:39 raspberrypi vncserver-x11[489]: Connections: connected: [email protected] (desde my_ip::port)
nov 23 18:08:39 raspberrypi vncserver-x11[489]: session started: user pi permissions f
nov 23 18:08:39 raspberrypi vncserver-x11[489]: Connections: authenticated: [email protected] (desde my_ip::port), as
nov 23 18:08:40 raspberrypi vncserver-x11[489]: SPrintConnMgr: Failed to add printer: server-error-service-unavailable
nov 23 18:08:47 raspberrypi systemd[1]: systemd-fsckd.service: Succeeded.
nov 23 18:09:03 raspberrypi systemd-timesyncd[321]: Synchronized to time server for the first time 181.224.249.90:123 (2.debian.poo
nov 23 18:09:03 raspberrypi CRON[378]: (CRON) info (No MTA installed, discarding output)
nov 23 18:09:03 raspberrypi CRON[378]: pam_unix(cron:session): session closed for user root
nov 23 18:09:11 raspberrypi systemd[1]: systemd-hostnamed.service: Succeeded.
what seem curious is at the start, the error in:
from scipy.spatial import distance as dist.
ImportError: No module name scipy.spatial
When I run the bash alone got no problem with the library.
sleep 3
to likesleep 10
? Maybe the X server didn't start in time...sleep
to cron doesn't seem to resolve the OP's issue.