Though this is not a Raspberry PI question, I am seeing this is being asked often nowadays
This is what worked for me with Raspberry Pi OS (Debian 10)
This was done on Debian with LXDE desktop. I wrote an automated setup script for my software, copying some snippet from that here.
Step 1. Disable the LXDE desktop:
I had commented out lxpanel and xscreensaver both from the default autostart and user autostart
#DISABLE THE DESKTOP sudo sed -i 's/^@lxpanel/#@lxpanel/g' /etc/xdg/lxsession/LXDE/autostart sudo sed -i 's/^@xscreensaver/#@xscreensaver/g' /etc/xdg/lxsession/LXDE/autostart #DISABLE THE DESKTOP FOR THE USER sudo sed -i 's/^@lxpanel/#@lxpanel/g' /etc/xdg/lxsession/LXDE-${user_name}/autostart sudo sed -i 's/^@xscreensaver/#@xscreensaver/g' /etc/xdg/lxsession/LXDE-${user_name}/autostart
Step 2. Setup the application:
Note: I was using python3.7
#SETUP PYTHON VENV python3 -m venv ${application_root_dir}/venv cd ${application_root_dir}/venv source ${application_root_dir}/venv/bin/activate # Install external dependencies, if any pip3 install <dependecny_name> # Install your software pip3 install <software> deactivate
Step 3. Prepare for Autostart (optional):
Create Script to be executed in autostart. Note this is optional, you can directly use your command in the auto start (step 4).
tee -a ${application_root_dir}/start_my_app.sh > /dev/null << EOT #!/bin/bash cd ${application_root_dir} source venv/bin/activate python3 -m package.MyApp deactivate EOT # Set execute permissions sudo chmod 744 ${root_dir}/start_my_app.sh
Step 4. Setup Autostart:
Note: you can execute any command by setting ExecStart in [service]
4.1 Create a new service
# CREATE A SERVICE FILE sudo tee -a /etc/systemd/system/my_app.service > /dev/null << EOT [Unit] Description=Start MY_APPLICATION After=default.target Wants=default.target [Service] User=${user_name} Group=$user_group Environment=DISPLAY=:0.0 Environment=XAUTHORITY=/home/${user_name}/.Xauthority ExecStart=/bin/bash -c "${root_dir}/start_my_app.sh" [Install] WantedBy=default.target EOT
4.2 Register and enable the service
sudo /usr/bin/systemctl daemon-reload sudo /usr/bin/systemctl enable my_app.service
4.3 Reboot
sudo reboot
Note: To enable the desktop back for troubleshooting (if at all required - I never needed though, as ssh was enabled in my case so I was using terminal). Uncomment the commented part of lxde deskop and reboot.
how to start a program instead of a DM (desktop manager)