简体   繁体   中英

How can I make a Python program executable so that it automatically runs

我有一个非常基本的Python程序,该程序会在某些时间间隔向您发出警报...我想使其成为一种软件,这样我就不必在每次打开计算机时都运行该程序... Windows和Linux...。还有一种通用的方法可以从任何语言的源代码创建可执行文件

For Linux , you can specify your .py(script) file and then have a cron job to run it based on your setup. You can schedule script to be executed periodically. Your cron job script can be edited as: Opens crontab edit:

# crontab -e

And add following entry if you want a scheduled job:

0 6 * * * /usr/bin/python your_script.py

So this will run every day at 6 am. For more options refer to http://www.adminschoice.com/crontab-quick-reference

Or if you want to add it to run at startup add the following entry:

@reboot  /usr/bin/python your_script.py &

For Windows create a batch job and append it to your startup schedule, so this will run whenever you boot up your system.

  1. batch file can be like(given you have a installed python version in your system):

     @echo off python your_script.py PAUSE 
  2. save it as some_name.bat
  3. Create a shortcut of the file in startup folder(which can be opened using RUN > shell:startup)
  4. Paste your batch file shortcut in above location.

  5. For scheduled run for python script in windows refer to https://www.esri.com/arcgis-blog/products/product/analytics/scheduling-a-python-script-or-model-to-run-at-a-prescribed-time/

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