I have a script that i run every day and want to make a schedule for it, i have already tried a batch file with:
start C:\Users\name\Miniconda3\python.exe C:\script.py
And im able to run some basic python commands in it, the problem is that my actual script uses some libraries that were installed with Anaconda, and im unable to use them in the script since Anaconda will not load.
Im working on windows and can't find a way to start Anaconda and run my script there automatically every day.
In order to schedule the Python script using the Windows Scheduler: Open the Windows Control Panel and then click on the Administrative Tools. Double-click on the Task Scheduler, and then choose the option to 'Create Basic Task…' Type a name for your task (you can also type a description if needed), and then press Next ...
How to Run a Python Script. If you created the file in the Anaconda Spyder IDE, you can run the script by clicking on the green triangle (the Run button) in the upper-lefthand corner of the IDE. When you click the Run button, you'll see the output displayed in the Python console in the lower-righthand pane of the IDE.
First, create your Python script. Then, open the system terminal your working with. To access crontab, input 'crontab -e' (one will be created if it doesn't already exist). Then enter 'i' to initiate the edit mode, and proceed to input your schedule command.
I would be a bit careful in calling python directly through environment as one never knows if the internals for activate function has changed.
I'm just using basic bat-script to help me out.
SET log_file=%cd%\logfile.txt call C:\Anaconda3\Scripts\activate.bat cd \script_directory python script.py arg1 arg2 > %log_file%
This script saves the log-file wherever the bat is run from, calls the right environment through activate (in this case the standard) and directs all the stdout into log-file for further investigation.
Then just point your Windows Task Scheduler to the script and set the home directory where you want the log-file to appear.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With