在Windows上通过批处理计划Python脚本(使用Anaconda) [英] Schedule a Python script via batch on windows (using Anaconda)

查看:374
本文介绍了在Windows上通过批处理计划Python脚本(使用Anaconda)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个每天运行的脚本,想要为其制定时间表,我已经尝试使用:

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

而且我无法在其中运行一些基本的python命令,问题是我的实际脚本使用了随Anaconda安装的某些库,由于无法加载Anaconda,因此我无法在脚本中使用它们.

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.

我在Windows上工作,找不到每天启动Anaconda并在其中自动运行脚本的方法.

Im working on windows and can't find a way to start Anaconda and run my script there automatically every day.

推荐答案

在通过环境直接调用python时,我会有些谨慎,因为永远不知道Activate函数的内部结构是否已更改.

I would be a bit careful in calling python directly through environment as one never knows if the internals for activate function has changed.

我只是使用基本的bat脚本来帮助我.

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%

此脚本将保存蝙蝠从何处运行的日志文件,并通过激活(在本例中为标准)调用正确的环境,并将所有stdout定向到日志文件中以进行进一步调查.

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.

然后将Windows Task Scheduler指向该脚本,并设置要在其中显示日志文件的主目录.

Then just point your Windows Task Scheduler to the script and set the home directory where you want the log-file to appear.

这篇关于在Windows上通过批处理计划Python脚本(使用Anaconda)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆