Skip to content

Instantly share code, notes, and snippets.

@RGD2
Last active September 3, 2021 05:38
Show Gist options
  • Save RGD2/dc8bd95a798c62ff848eea74aab859ac to your computer and use it in GitHub Desktop.
Save RGD2/dc8bd95a798c62ff848eea74aab859ac to your computer and use it in GitHub Desktop.
Jupyter lab on Windows 10 with a nice desktop shortcut and working matplotlib widgets
  • install from microsoft store:
    • debian/WSL2
    • windows terminal
  • check at https://aka.ms/wsl2 for how to set that up. Requires a reboot, or else you won't get WSL2 to work and jupyter will be so slow as to be barely usable.
  • today (2021-08-18) there were a couple new 'wrinkles':
  • I was going to build latest python3.9.6 from source ( which did work) but decided to just stay with the version in debian 11, since it wasn't that old (3.9.2), hence the long apt-get install line.
  • this setup follows the rule that its better to use pip in a virtualenv than it is to try to get things installed via system package, especially for jupyter lab.
  • node installation is actually as suggested by MSFT, nvm is quite nice.
echo "$USER ALL=(ALL:ALL) NOPASSWD: ALL" | sudo tee /etc/sudoers.d/dont-prompt-$USER-for-sudo-password
cat <<EOT | sudo cat >/etc/apt/sources.list
deb http://deb.debian.org/debian bullseye main
deb http://deb.debian.org/debian bullseye-updates main
deb http://deb.debian.org/debian-security/ bullseye-security main
deb http://ftp.debian.org/debian bullseye-backports main
EOT
sudo apt update
sudo apt upgrade -y
sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libsqlite3-dev libreadline-dev libffi-dev curl libbz2-dev lzma-dev python3 python3-distutils
sudo python3 -m pip install virtualenv virtualenvwrapper
cd
mkdir .venvs
cat <<EOT >>.bashrc
export WORKON_HOME=$HOME/.venvs
export VIRTUALENVWRAPPER_PYTHON=/usr/bin/python3
source /usr/local/bin/virtualenvwrapper.sh
EOT
wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.38.0/install.sh | bash
source .bashrc
nvm install --lts
nvm use --lts
mkvirtualenv jupenv
pip install jupyterlab
jupyter labextension install @jupyter-widgets/jupyterlab-manager jupyter-matplotlib
pip install ipympl numpy pandas

sudo apt install gnupg2 apt-transport-https
wget -O - https://pkg.wslutiliti.es/public.key | sudo tee -a /etc/apt/trusted.gpg.d/wslu.asc
echo "deb https://pkg.wslutiliti.es/debian buster main" | sudo tee /etc/apt/sources.list.d/wslu.list
sudo apt update
sudo apt install wslu
jupyter lab --generate-config

cat <<EOC >> ~/.jupyter/jupyter_lab_config.py
c.ServerApp.allow_origin = '*'
c.ServerApp.browser = 'wslview %s'
c.ServerApp.use_redirect_file = False
EOC
sudo apt install -y ufw
sudo ufw allow 8888
echo "c.ServerApp.ip = $(ip -4 a show dev eth0 | grep inet | cut -d' ' -f 6 | cut -d'/' -f 1)" >> ~/.jupyter/jupyter_lab_config.py

cat << EOF > ~/jup.sh
#!/bin/bash
cd
source $(which virtualenvwrapper.sh)
workon jupenv
jupyter lab
EOF
chmod +x jup.sh
wget "https://upload.wikimedia.org/wikipedia/commons/3/38/Jupyter_logo.svg"
convert -density 256x256 -background transparent Jupyter_logo.svg -define icon:auto-resize -colors 256 jupyter.ico
rm Jupyter_logo.cvg
exit
  • Right-click on the desktop, and select: New -> Shortcut
    • It will prompt you for a program to run, input: wsl.exe bash -ic ~/jup.sh
    • Name it 'Jupyter Lab'
  • Right click on the shortcut -> properties
    • on 'shortcut' tab, click 'Change Icon...'
      • put \\wsl$ into the location
      • navigate to your Debian/home/username/ directory
      • select jupyter.ico

(note^[if you add a network share (to /etc/fstab, with cifs, for example) then you should probably mount it or at least symlink the mount dir into linux home, and also add a line to the above script before starting jupyter lab, something like sudo mount -a to auto-remount everything. You can also do it from within jupyter (add a ! to the front, and put it in a cell and run it with shift-enter) since that can be done at any time.])

When you open Jupyter, it will open a console window with the server in it, then will open your preferred web browser with the jupyter lab GUI. You need to leave that console window open whilst you're running it.

MAKE SURE YOU SAVE BEFORE CLOSING THE WINDOW OR STOPPING THE SERVER! (just closing the window will lose any changes to any file you have open in it since last save - although you might get lucky if you look into ipython history... if it was turned on...) You can kill the server (AFTER SAVING YOUR WORK!) by going to the console window, and typing ctrl-c twice, or just using 'shutdown' from the menu in jupyter (it will just shutdown jupyter).

I found that the example ipympl notebook has good information on getting sliders working with interactive plots. This works along with pandas for loading and sorting through data. I also like tqdm (install via pip) which is good for nice progress bars when doing slow things, keeps you from getting anxious that it's crashed or just gotten stuck, and gives a simple ETA.

@RGD2
Copy link
Author

RGD2 commented Sep 2, 2021

I'm pretty sure this installs more packages than are strictly required.

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