Skip to content

Instantly share code, notes, and snippets.

@davecoutts
Created August 31, 2020 17:21
Show Gist options
  • Save davecoutts/ceacb1ecbc2ad261007c78b119befcc2 to your computer and use it in GitHub Desktop.
Save davecoutts/ceacb1ecbc2ad261007c78b119befcc2 to your computer and use it in GitHub Desktop.
Launch Anaconda installed JupyterLab in Windows. Specify the Browser and Working directory. Add JupyterLab Right-Click launch in Windows Explorer.
@echo off
rem ---------------------------------------------------------------------------
rem Launch Anaconda installed JupyterLab from Windows
rem ---------------------------------------------------------------------------
rem Author: Dave Coutts
rem License: Apache
rem Version: 1.0.0
rem Maintainer: https://github.com/davecoutts
rem Tested: With Anaconda3-2020.07-Windows-x86_64.exe and Windows 10 2004 on 31st August 2020.
rem Usage:
rem
rem Run jupyterlab_launcher.bat without any variables passed into it and
rem it will launch JupyterLab with the working directory set to the
rem directory the bat file is placed in.
rem
rem Run jupyterlab_launcher.bat with a directory variables as the first
rem argument and it will launch JupyterLab with the working directory set to
rem that directory.
rem
rem e.g. jupyterlab_launcher.bat
rem jupyterlab_launcher.bat C:\Users\dave
rem jupyterlab_launcher.bat %ONEDRIVE%
rem Tip: The jupyter icon can be found here %USERPROFILE%\Anaconda3\Menu\jupyter.ico if you are making a shortcut.
rem ---------------------------------------------------------------------------
rem Set the JupyterLab notebooks working directory.
if [%~1]==[] (
set NOTEBOOKDIR=%~dp0
) else (
set NOTEBOOKDIR=%1
)
rem Default location in which Anaconda is installed on Windows 10.
set ANACONDA_BASE=%USERPROFILE%\Anaconda3
rem Set the browser that JupyterLab will launch.
set SESSION_BROWSER=%PROGRAMFILES(x86)%\Google\Chrome\Application\chrome.exe
set SESSION_BROWSER=%PROGRAMFILES%\Google\Chrome\Application\chrome.exe
set SESSION_BROWSER=%PROGRAMFILES%\Mozilla Firefox\firefox.exe
rem Launch JupyterLab.
%ANACONDA_BASE%\python.exe ^
%ANACONDA_BASE%\cwp.py ^
%ANACONDA_BASE% ^
%ANACONDA_BASE%\python.exe ^
%ANACONDA_BASE%\Scripts\jupyter-lab-script.py ^
--browser="'%SESSION_BROWSER%' %%s" ^
--notebook-dir=%NOTEBOOKDIR%
exit
rem ---------------------------------------------------------------------------
Windows Registry Editor Version 5.00
; Run this Windows Registry file to add Right-Click Windows Explorer launch of JupyterLab via jupyterlab_launcher.bat
; The JupyterLab working directory will be set to the directory the Right-Click launch is made from.
; Edit the path to the jupyterlab_launcher.bat file in the last line of this file to suit your installation configuration.
[HKEY_CLASSES_ROOT\Directory\Background\shell\JupyterLab]
@="JupyterLab"
[HKEY_CLASSES_ROOT\Directory\Background\shell\JupyterLab\command]
@="cmd.exe /c start \"JupyterLab\" /min \"C:\\Users\\dave\\Documents\\jupyterlab_launcher.bat\" %V"
@davecoutts
Copy link
Author

I wrote this BAT file so I could Right-Click launch JupyterLab in a working directory chosen from Windows Explorer.

Place the jupyterlab_launcher.bat file is a directory and alter the last line of the jupyterlab_launcher.reg Windows Registry file to match the location of the bat file before running/importing the registry file. After the registry file import is complete you should see 'JupyterLab' as a Right-Click option in Windows Explorer.

To change the browser that JupyterLab launches, alter the SESSION_BROWSER variable in the bat to a browser of your choosing.

The bat file can be used on its own if you don't need Right-Click launch integration.
Simply place the bat file in the desired notebook working directory and run it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment