Schedule a Python script via batch on windows (using Anaconda)(在 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)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 Windows 上通过批处理调度 Python 脚本(使用 Ana
基础教程推荐
- 究竟什么是“容器"?在蟒蛇?(以及所有的 python 容器类型是什么?) 2022-01-01
- 比较两个文本文件以找出差异并将它们输出到新的文本文件 2022-01-01
- 对多索引数据帧的列进行排序 2022-01-01
- 在 Django Admin 中使用内联 OneToOneField 2022-01-01
- 在 Python 中将货币解析为数字 2022-01-01
- Python,确定字符串是否应转换为 Int 或 Float 2022-01-01
- matplotlib 设置 yaxis 标签大小 2022-01-01
- kivy 应用程序中的一个简单网页作为小部件 2022-01-01
- Kivy 使用 opencv.调整图像大小 2022-01-01
- Python 中是否有任何支持将长字符串转储为块文字或折叠块的 yaml 库? 2022-01-01
