How to autorun a Python/Bash Script in headless mode.

I need to run a python script when Rpi is turn on, I was using a python virtual environment so I was created a script for the autorun and added on the .bashrc, but the script only starts when connecting a GUI or start new SSH session, it won’t automatically start in headless mode.

Model: Raspberry Pi B

OS: Raspbian Strech


bash script :


source /home/pi/.profile
workon cv5
cd /home/pi/Desktop

Hi all,

found the solution, my goal is to run a python script that uses a virtual environment, so first wrote a bash script to automate the virtual environment setup then added bash script on them .bashrc


source /home/pi/.profile
workon cv
cd /home/pi/pi-reboot

but the script won’t run until I open the terminal (IDK why), and my application must need to work on the headless environment, so I disabled the GUI and enabled the autologin in the terminal via </s>raspi-config <e>

Thank You.