Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Subsystem for Linux (WSL 2) and Jupyter Lab : How to open a Jupyter Notebook saved at the Linux file system?

I have a Jupyter lab installed on Windows. I installed Jupyter Lab on WSL Ubuntu. I can lunch Jupyter Lab from Linux terminal. This will open Jupyter Lab on Chrome browser from which I can start a new Jupyter Notebook with Python [conda env:root]*. However, it only shows the windows file system. I try to open my note book that is saved on the Linux file system using:
$ jupyter lab my_linux_folder/my_notebook.ipynb

Jupyter lab lunches successfully, but cannot open the notebook that is on the Linux file system and gives an error:

Cannot open
Could not find path: /my_notebook.ipynb

Is it possible to open a notebook that is on the Linux file system "\wsl$\" and how?
How to go to "\wsl$\" from JupyterLab file browser?
Or more generally how to open a notebook that is saved under "\wsl$\" ?

like image 648
ASE Avatar asked Jun 12 '20 23:06

ASE


People also ask

How to configure Jupyter Notebook in Windows Subsystem Linux (WSL2)?

Configuring Jupyter Notebook in Windows Subsystem Linux (WSL2) 1 First, install WSL2. ... 2 Update your Linux 3 Install Miniconda. ... 4 Install libraries & tools 5 Launching Jupyter Lab and Note ... 6 Jupyter Lab 7 Jupyter Notebook. ... 8 Problems resolving localhost. ... 9 Install Graphic Interface and ... 10 Helpful resources. ... 更多结果...

What is the difference between Jupyter Notebook and Jupyter lab?

I prefer Jupyter Lab to Notebook because it gives you more flexibility to open multiple windows under the same tab browser, allowing you to open multiple files besides a command prompt. And to choose to avoid the message error, run each command with the no-browser parameter And copy and paste the full URL, including the token.

How to install Jupyter in Linux without browser?

Install Jupyter by typing the following command in your Bash Shell. 2. Create alias to launch jupyter without browser from the WSL: Open your bash configuration and type: Next you will get something like this where you have to find esac. Next you have to Press Ctrl + X and type Y for Yes and press enter which will take you back to your bash shell.

What is OpenWindows subsystem for Linux (WSL)?

Windows Subsystem for Linux ( WSL) is a compatibility layer for running Linux binary executables natively on Windows 10! It also has the added benefit of you getting full admin rights to the subsystem once installed. First off we have to do some preliminary setup to get WSL working:


2 Answers

WSL 2 issues a dynamic IP address each time you launch WSL 2 -- see MSFT docs.

Personally, I run a Python command within a subshell to print that IP:

jupyter lab --ip $(python3 -c "import subprocess; subprocess.run(['hostname', '-I'], text=True).stdout")

This works for me on Ubuntu 20.04 and Windows 10 build 19041.329.

Note: You'll likely have to visit that IP address instead of localhost, plus the port through which you're running Jupyter, e.g. http://:8888 .

To get my IP address via the CLI I use:

ip addr | grep eth0 | grep inet

I choose the first IP address available, typically using that address without the subnet mask, i.e. the forward slash + number.

like image 71
Jason R Stevens CFA Avatar answered Sep 22 '22 13:09

Jason R Stevens CFA


Update:

You can access the Linux files by modifying the configuration file. You'll need to allow root access and specify the Jupyter Notebook directory. The directory starts from the root directory of the Linux file system. You can also start from the Windows file system /mnt/c/users/admin/.jupyter.

{
    "NotebookApp": {
        ...
        "allow_root": true,
        "notebook_dir": "/home/admin/.jupyter",
        ...
    }
}

Original:

Is there a particular reason you need to save the Jupyter Notebook files on the Linux file system? WSL has full access to the Windows file system so it shouldn't matter where the file is saved.

To add to Jason's point:

Apparently, WSL 2 uses a virtual network adapter that has its own IP address. It also changes the IP address every time the server is restarted. It got annoying having to manually update the IP address so I wrote a script to update it automatically.

I wrote an article about how to do it to make it easier for everyone:

How to Set Up the Jupyter Notebook Home and Public Server On Windows Subsystem for Linux 2 (WSL2)

The attached photo is a Notebook running on WSL 2 that's saved on the Windows 10 file system.

enter image description here

like image 21
david-littlefield Avatar answered Sep 22 '22 13:09

david-littlefield