2. Jupyter Lab environment construction tutorial

1. Introduction to JupyterLab

JupyterLab is an interactive development environment and the next generation product of Jupyter notebook. It integrates more functions, supports plug-in extensions, and can be run through the web page. It is simple, convenient and powerful. It is a very worthwhile code editing tool.

2. Switch to the root user

You need to use the root user to install jupyterlab, and the root user of the Ubuntu Mate 20.04 system has no password by default and cannot be switched, so you need to set a password for root before you can use the root account.

Note: The password set for root here must be remembered. It is best to keep it consistent with the user's password so that it will not be easily forgotten. Once forgotten, the consequences are serious.

  1. Enter the following command to set a password for root, and then enter the same password twice to confirm.

sudo passwd

  1. Switch to root user

sudo su

From the above picture, you can see that you have switched to the root user. And the $ symbol before the edit command has been changed to the # symbol.

3. Install JupyterLab

  1. Install ffi library

apt-get install libffi-dev

  1. Install jupyter

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyter

  1. Install jupyter lab

pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple jupyterlab

  1. After the installation is complete, switch back to the normal user

su dofbot

4. Configure JupyterLab

  1. Generate a configuration file

jupyter notebook --generate-config

  1. Use ipython to generate the login password for jupyterlab.

ipython

In In [1], enter: from notebook.auth import passwd

In In [2], enter: passwd()

Then enter the same password twice and press Enter to confirm. Note that the password here is used to log in to the jupyterlab interface. For easy memorization, it can be consistent with the user password.

Then the system will output the ciphertext of the password. Copy the entire ciphertext. The ciphertext generated for each password may be different. Please copy the actual output ciphertext.

Enter in In [3]: exit()

  1. Compile the jupyter configuration file

nano ~/.jupyter/jupyter_notebook_config.py

Go directly to the end and add the following content:

c.NotebookApp.ip = '0.0.0.0'

c.NotebookApp.open_browser = False

c.NotebookApp.password = Entire password ciphertext

c.NotebookApp.port = 8888

Finally save and exit.

5. Install jupyterlab plugin

  1. Install nodejs and npm

sudo apt install nodejs npm

  1. Install jupyter widget extension plugin. Since it needs to be downloaded and compiled, it takes a long time to run and may fail. If an error occurs, re-run the installation.

sudo jupyter labextension install @jupyter-widgets/jupyterlab-manager

  1. Install statusbar plugin

sudo jupyter labextension install @jupyterlab/statusbar

  1. At this point, jupyterlab has been installed.

6. Start jupyterlab

  1. Enter the directory where you want to run the code. Here, we take a new test folder as an example.

mkdir test

cd test

  1. Open jupyterlab

jupyter lab

This port number is the port number we need to access. By default, it is the port number indicated by c.NotebookApp.port in the jupyter configuration file in the previous step. If you open a jupyterlab service, the port number will automatically increase by 1, so that different jupyterlab services can be distinguished.

7. Remote access to jupyterlab

  1. Open the browser on the computer (Chrome or Firefox is recommended), and then enter the motherboard IP: port number. Here, take IP 192.168.2.102 and port 8888 as an example.

http://192.168.2.102:8888/

The jupyterlab interface will pop up and ask you to enter the password. Just fill in the jupyterlab login password set above.

  1. If you see the following interface, it means that the remote login to jupyterlab is successful. You can create a new Python3 program to run.

8. Exit jupyterlab

Press Ctrl+C twice on the terminal where jupyterlab was just opened to exit jupyterlab.