Python Scripts autorun at Startup

hello everyone,
i need a solution for autorun my python scripts after boot and they will run on terminal.
I have already tried startup application mathon and they ain't working.I also used .sevice and it also not working!

Hi Vikas, welcome to the community

I do not have a complete picture yet of what you exactly want to do, but I do have some info that might be helpful ( I hope) :

User level (after login)

An article about autostarting applications:
https://www.addictivetips.com/ubuntu-linux-tips/automatically-start-programs-on-mate/

To summarize it a bit:
create a .desktop file for your script, move it to the ~/.config/autostart directory and make it executable or let the GUI do this all for you.

If it has to run in a terminal, make sure that the line Terminal=true is present in the .desktop file.
or in the GUI entry you created.

System level (before login)

If you want your scripts to run before login, you officially should create a systemd unit file to start your scripts:

but there is already another possibility build-in. It's the legacy /etc/rc.local which is, only in ubuntu and some other distros , automatically started by systemd if it exists (and which I use because I'm a lazy bastarძ). If it doesn't exist yet, follow this:

Be aware that you don't have an environment before login:
That means that you have to setup your environment yourself or use full pathnames for everything you do (and don't rely on environment variables because there are none yet)

Also, you can't have an interactive terminal at this stage since you're not logged in yet (unless you do some arcane system level black magic :wink: )

Also, a lot of people start their script with #!/usr/bin/env python
Since there is no environment yet , i have strong doubts about that something like that would work.
(i am not sure because i don't use python for system level scripts)
So you could try this #!/usr/bin/python ( which is also a slightly better practice on system level security wise but that is a completely different topic)

I hope any of this is of any help :slight_smile: