How can I run jupyter notebook in background on windows ?
Asked Answered
P

5

9

I want to run jupyter notebook on windows, but it always left a blocking terminal "window command prompt", how can I avoid it and let the jupyter server run in background?

Purim answered 30/6, 2016 at 8:50 Comment(1)
I've written a blog post about how to do this with scheduled tasks hereDarky
P
4

I want to do this too and have found a solution from my friends, but i can't understand it,because i kown fewer about windows commond line. here is the solution, i test it on win8 and win10:

First: create a new .bat file and add below line to the file:

jupyter notebook

before this, you should be sure that you can run jupyter notebook on the cmd by type the command of 'jupyter notebook'. when finished,better to double click this .bat file and test if it could run jupyter notebook. e.g. this file is named as jupyter.bat.

Second: create a new .vbs file and add this tow line to the file:

Set ws = CreateObject("Wscript.Shell")
ws.run "cmd /c jupyter.bat",vbhide

the jupyter.bat should be changed to you .bat file, and save this file, double click it. then the jupyter run as a background process. note that, when you double click .vbs file, there is nothing for prompt. and when you want to shut down jupyter, open task manager, find python process, close it.

good luck!

Personify answered 14/11, 2016 at 3:44 Comment(1)
I want the ability to start the .vbs from any directory on command prompt. Please share your experience if you are able to do it. I think we need to modify "PATH" or "Path" environment variable , but not sure which one. Does it depends on the way jupyter notes was installed ( for all user vs single user)?Hardiman
T
4

On Windows, many people use unix terminal emulators: Cygwin, MSYS2, WSL for Windows 10. You can easily give it a try by downloading the Git for Windows command line — no administrator rights or password required, either.

Your shell's configuration file is typically found in ~/.bashrc. I have added the following aliases to it:

alias jn="cd $HOME && jupyter notebook &> /dev/null &"
alias jnk='ps -W | grep "jupyter-notebook" | awk "{print \$1}" | xargs kill -f'

The first one simply starts a jupyter notebook in the background by redirecting both stdout and stderr to /dev/null, and gives you the PID of the process:

$ jn
[1] 9524

The second simply kills any process that's got the name jupyter-notebook:

$ jnk
[1]+  Done  cd $HOME && jupyter notebook &> /dev/null

I know this only answers the answer diagonally, but hope you'll find it useful nonetheless.

Triphibious answered 4/5, 2017 at 14:34 Comment(1)
confirm this work even with warning box when I closed the warning box.Pennate
C
1

Try

start /min jupyter notebook

It will still open a window but that is minimized.

Copenhagen answered 16/3, 2020 at 14:15 Comment(0)
T
1

For Jupyter Lab (Anaconda) to start as a background service, (which requires admin access) on start up of windows 11, I scheduled a task, as follows,

Action: Start a Program

Program/Script: %windir%\System32\WindowsPowerShell\v1.0\powershell.exe

Add Arguments: -ExecutionPolicy ByPass -NoExit -Command "& 'C:\ProgramData\Anaconda3\shell\condabin\conda-hook.ps1' ; conda activate 'C:\ProgramData\Anaconda3' ; Start-Job -ScriptBlock {cd C:\Users<user-account><path-to-workspace> ; jupyter lab}";

Still exiting the Power shell closes the Jupyter Lab Session, though! :( . Posting here for someone to improve this answer further.

Tailing answered 24/5, 2022 at 0:59 Comment(0)
G
0

As mentioned by @nathan, a task scheduler was useful in my case:

  1. create a .bat file inside the user directory directory %USERPROFILE%\jup.bat with below commands:
call "C:\my_python_envs\mypyenv\Scripts\activate.bat" && jupyter notebook --notebook-dir="D:\programming\"
  1. Create a task in Windows task scheduler with path to this batch file.
Gahnite answered 9/9, 2024 at 5:20 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.