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

查看:31
本文介绍了在 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:

启动 C:Users ameMiniconda3python.exe C:script.py

start C:Users ameMiniconda3python.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 时我会小心一点,因为永远不知道激活函数的内部是否发生了变化.

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:Anaconda3Scriptsactivate.bat
cd script_directory
python script.py arg1 arg2 > %log_file%

此脚本会在运行 bat 的任何位置保存日志文件,通过 activate(在本例中为标准)调用正确的环境并将所有标准输出定向到日志文件中以供进一步调查.

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 任务计划程序指向脚本并设置您希望日志文件出现的主目录.

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天全站免登陆