简体   繁体   中英

Python Auto run files on startup

I have made an alexa like program on python. Now, I want it to auto run when I start my computer and take inputs and give outputs as well. How do I do it?

- For linux

First make sure you add this line to the top of your python program.

#!/usr/bin/python3

  • Copy the python file to /bin folder with the command.

sudo cp -i /path/to/your_script.py /bin

  • Now Add a new Cron Job.

sudo crontab -e

This command will open the cron file.

  • Now paste the following line at the bottom of the file.

@reboot python /bin/your_script.py &

  • Done, now test it by rebooting the system

You can add any command to run in the startup in the cron file.

Cron can be used to perform any kind of scheduling other than startup also.

- For Windows

Navigate to C:\Users\ username \Appdata\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

Place your complied exe file there, it will be executed on startup.

To make exe from py, first install the pyinstaller module pip install pyinstaller .

Now run the command in the folder where the python file is pyinstaller --onefile your_script.py

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM