Jupyter Lab & Linux on Windows: Level Up Your Data Science Setup
Access Linux for your data science projects without leaving Windows! This guide reveals how to run Jupyter Lab persistently within a Windows Subsystem for Linux (WSL2) environment, move files & more.
Jupyter notebooks and Jupyter Lab are everywhere these days! 🌎 From research labs 🔬 to data science projects 📈 and even AI/ML models 🤖, everyone loves these user-friendly environments that work with Python, R, JavaScript, and more! 🐍
But here's the thing... while we can mostly work in a happy OS-agnostic world, sometimes things just run smoother on Linux or macOS, especially when it comes to setting up Jupyter Lab environments.
What if you could harness the power of Linux without leaving your Windows system? 🎉 That's exactly what I recently shared with the audience at Virginia Tech – a simple trick to run Jupyter Lab natively in a Linux environment. This is part of a talk I gave at Virginia Tech recently where we were discussing configuring Jupyter lab environments on a Windows machine and I wanted to show them an alternative solution.
Here's what you'll get out of this setup:
Persistent Jupyter Lab: Run it without a command prompt window open, even after sleep or hibernation! 😴➡️🚀
Native Ubuntu: Install tools and Python packages just like you would on a real Ubuntu desktop. 📦
Easy File Access: Move files between Windows and your Linux environment with ease. 📁➡️📁
Setting Up the Magic: Windows Subsystem for Linux 2 (WSL2) ✨
This tutorial will walk you through using WSL2, a compatibility layer that lets you run Linux applications directly on Windows 10 or 11. It's like having a mini Linux computer inside your Windows system! 🤯
Already have WSL2? Great! Skip ahead. If not, there are plenty of tutorials online to help you get it set up.
Next up, I have an existing installation of Ubuntu 20.04 LTS but we'll install a fresh Ubuntu 22 environment in WSL2 and get Jupyter Lab running smoothly. 🚀
Installing Ubuntu 22: Easy Peasy! 🐧
Getting Ubuntu 22 on your system is a breeze! I simply headed over to the Microsoft Store typed in Ubuntu. Select Ubuntu 22.04.03 LTS and click get.
Once installed click open. It's just a few clicks and setting up a username and password, and you're good to go!
Jupyter Lab: Let's Get it Running! 🏃♀️🏃♂️
Now for the fun part - installing Jupyter Lab! You can choose to set it up in a virtual environment, but I went the easy route and installed it globally with superuser privileges. 🌎
Virtual environments are great for keeping your projects organized, but for a quick setup, a global install does the trick. If you're curious about virtual environments, check out this awesome primer.
Jupyterlab Start, Setup & Launch
You can run Jupyter lab by simply typing Jupyter lab in your terminal. But we are going to take a few steps and modify this a little bit. First of all we are going to set a password for Jupyterlab which allows us the ease of never copying of copy a unique url with token.
Let's make sure your Jupyter Lab session stays alive and kicking, even if you close your terminal window. For this, we'll use a nifty tool called tmux. Tmux, short for "Terminal Multiplexer," is a command-line tool that enables users to manage multiple terminal sessions within a single window or session. We are also modifying the basic command
No browser: We'll tell Jupyter Lab not to bother looking for a browser within WSL2. 🚫
Localhost access: We'll use 0.0.0.0 to make Jupyter Lab accessible from your Windows browser. 🌐
jupyter lab --no-browser --ip=0.0.0.0
With your Jupyter Lab server humming along in the background, it's time to get exploring! Head over to any browser on your Windows machine and type in localhost:8888
Persistent Jupyterlab
With our tmux setup, you can safely close both the tmux session and the WSL2 window, and your Jupyter Lab will keep running happily in the background. Apart from the fact that this is running completely on a Linux subsystem you no longer have a window open to run the Jupyter lab server which provides a clean look and feel to your setup.
Note: The Jupyter Lab server will shut down if you restart or shutdown your computer
Accessing JupyterLab and Your Files 📁
You can find and interact with all the files and folders within your Ubuntu setup just like you would with any other Windows folder! The WSL files and folders can be found by typing the following in your Explorer window
\\wsl.localhost
Let’s copy a file from a Windows folder to the folder where Jupyter lab is running. We used pwd to get the working directory.
This writeup is to allow users to experience a cleaner setup for the Jupyter lab environments. While the overall use of this extends beyond just the persistent Jupyter lab we have the option to test write-upout different environments and some native flexibility for installation of different libraries. Let's connect on Linkedin and Github to collaborate, share dataset ideas, provide valuable feedback, and join the exciting conversation! 💬🤝
We return with a data deep dive next week stay tuned for a deep dive on some ocean, shorelines and hydrology datasets.