I have a notebook that automatically queries a database, and then pushes the results to a google sheet every hour, but needs to be constantly running on a computer to work. How can I automatically run a Jupiter notebook when my computer starts up (I reboot a lot) Thanks!
4 Answers
I didn't actually tried with Anaconda but the solution should be comparable. The idea is to create vb
script and run it from the scheduled task.
Create jupyter-cron.vbs
Set run = WScript.CreateObject("WScript.Shell") run.Run "jupyter-notebook.exe --no-browser --notebook-dir=C:\Notebooks", 0, True
Note: Use --no-browser option to prevent browser to start. The script will run with the hidden window. Do not forget to update path to the notebook directory.
Create jupyter-cron.bat
start /B "C:\Windows\SysWOW64\cscript.exe" "C:\Localdata\jupyter-cron.vbs"
Note: This location applies for 64-bit system, for the 32-bit system use C:\Windows\System32\cscript.exe. Do not forget to update path to vbs script.

- 8,939
- 2
- 28
- 33
Here is how I got it working using Johnny's steps as a template. (I would have responded with a comment to his post but I don't have enough rep.)
- Created
jupyter.vbs
file like Johnny mentioned. Replace $pathToAnaconda with your path and $pathToJupyterDirectory with where you want your jupyter to open to.
Set WinScriptHost = WScript.CreateObject("WScript.Shell")
WinScriptHost.Run "C:\{$pathToAnaconda}\Anaconda3\Scripts\activate.bat & jupyter notebook --no-browser --notebook-dir=C:\{$pathToJupyterDirectory}", 0, True
Set WinScriptHost = Nothing
- Created
jupyter.bat
file like Johnny mentioned. Replace $pathToVbsScript with path to your vbs file you made in step 1.
start /B "C:\Windows\SysWOW64\cscript.exe" "C:\{$pathToVbsScript}\jupyter.vbs"
- Go to the Windows Start Menu and type Task Scheduler. Open it, click New Task, then continue with Johnny's step #3.

- 131
- 2
- 7
-
I set it up the same way you mentioned above, but nothing happens after jupyter.vbs is executed. I must be missing something, what goes into {$pathToJupyterDirectory}? Its the location where you .ipynb is rite? – vevek seetharaman Jun 30 '20 at 11:35
-
this one is perfect – Isaac Sim Sep 15 '21 at 06:08
This is what I do for this sort of thing making use of Windows Task Scheduler. The con to this method is your computer has to be on and connected to the internet, but if you're working anyway this sort of doesn't matter.
Save your notebook as a .py file to your local (C:/users/username) directory then create a batch file using Notepad with the following script:
@echo on
call c:\PROGRA~1\Anaconda3\Scripts\activate.bat activate YOURPYTHONENVIRONMENT
call C:\Users\username\.conda\envs\YOURPYTHONENVIRONMENT\python.exe "C:\Users\username\pythonfile.py"
pause
save the notepad file with the name 'filename.bat' with filename being replaced with whatever you want. Save the bat file wherever, I save by bat files on my work drive.
Then open windows task schedule and create a basic task
- Give it a name
- Set the schedule
- Select "Start a Program" as the action you want to perform
- Copy and paste the path to the bat file in the program/script bar
Then finish and you're done, the program will execute automatically without opening jupyter on your schedule.

- 39
- 9
I suggest you to use papermill
library. It allows you to run a Jupyter notebook with command line. And you don't need instance of Jupyter running in the background.
check this answer: how to run a python jupyter notebook daily automatically
Then, schedule a hourly task with Task Scheduler in Windows, which will be executed when your computed will be switched on.

- 6,078
- 3
- 18
- 31