問題描述
我有一個每天運行的腳本并想為它制定一個時間表,我已經嘗試了一個批處理文件:
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)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!