Two or three months ago, I was lucky to get a 4-core 16G, 1TB hard disk of Cloud Raft with 300M bandwidth located in the Cloud Server in Europe. The RStudio Server that comes with it is also very powerful out of the box. However, I met a lot of problems in upgrading R in the last two days, so I don’t bother to toss about any more. So I want to replace RStudio Server with JupyterLab Server, which I am more familiar with. Here are some torturous notes. \

JupyterLab is a next-generation web-based user interface for Project Jupyter. JupyterLab enables you to work with documents and activities such as Jupyter notebooks, text editors, terminals, and custom components in a flexible, integrated, and extensible manner.



\

1. Install

JupyterLab can be installed by conda, PIP, Pipenvordocker.

# conda
conda install -c conda-forge jupyterlab

# pip
pip install jupyterlab
Copy the code

Nb_conda_kernels is an extension function of Jupyter. It can manage the Kernels of Jupyter in multiple Conda environments and integrate different versions of Python and R languages in multiple Conda environments.

1.1 installation nb_conda_kernels

Nb_conda_kernels must be installed in the Conda environment of Jupyter (Jupyter Notebook or JupyterLab). Nb_conda_kernels can be directly installed in the Base environment or created in an independent Conda environment.

Here we set up a new Conda environment specifically for placing JupyterLab:

Conda create --name JupyterLab python=3.7 jupyterlab
Copy the code

Nb_conda_kernels extension suite

Conda install --name jupyterlab NB_conda_kernelsCopy the code

1.2 Installing Jupyter Kernels

To use The Conda environment through NB_conda_kernels in Jupyter, you need to install the Corresponding Jupyter core (Kernels).

Create a Conda environment for Python 2.7:

# set up Python2.7Conda create --name Python2 python=2.718.Conda install --name Python ipykernelCopy the code

Set up a R-4.0.2 Conda environment:

# set up R4.02.Conda create --name R4.02. --channel r r-essentials=4.02. r-base=4.02.Conda install --name R4.02. --channel r r-irkernel
Copy the code

2. Start

After installing all Conda environments and corresponding Jupyter cores, you can start JupyterLab in the usual way:

$Conda activate Jupyterlab $source Activate Jupyterlab $Jupyter lab --ip0.0. 0. 0 --port 9090
Copy the code

Various Conda environment and language versions of JupyterLab

In this way, languages and versions of different Conda environments can be used simultaneously in a single JupyterLab interface. \

3. Configure remote access

3.1 Enter the IPython environment and generate the secret key

Assuming you are already in the IPython environment, follow the steps below to generate the secret key.

In [1]: from notebook.auth import passwd
In [2]: passwd() Enter password: # fill in your password (for accessing jupyterlab) Verify password: # fill in your password again2] :'argon2:$argon2id$v=19$m=10240,t=10,p=8$ShdM5... vHBHA$EUCjIE1L8joDbugmWIDqLw'# This is the key generated by your passwordCopy the code

3.2 Generating the JUPyterlab Configuration File

Use the –generate-config parameter to generate the JUPyterlab configuration file.

$ jupyter lab --generate-config
Writing default config to: /home/shenweiyan/.jupyter/jupyter_notebook_config.py
Copy the code

3.3 Modifying the Configuration File

The default JupyterLab configuration file is located at ~/. Jupyter /jupyter_notebook_config.py.

The changes are as follows:

Set IP to *, allowing any IP to access c.notebookapp.ip =The '*'# The password here is filled in with the key generated above c. notebookapp.password ='argon2:$argon2id$v=19$m=10240,t=10,p=8$ShdM5... vHBHA$EUCjIE1L8joDbugmWIDqLw'Open jupyter c. tebookapp. open_browser = False8888Or other c.notebookapp.port =8888# allow remote access c. notebookapp. allow_remote_access = TrueCopy the code

Next input JUPyter Lab can start jupyter- Lab services! \

4. Configure the domain name

Here is an example of JupyterLab forwarding via Nginx.

upstream jupyter {
    server 127.0. 01.:9090;
}

server {
    listen 80;
    server_name jupyter.bioitee.com;
    rewrite ^/(.*) https://jupyter.bioitee.com/$1 permanent;
}

server{
    listen 443 ssl;
    index index.html index.htm index.php default.html default.htm default.php; server_name jupyter.bioitee.com; root /data/apps/jupyterlab/notebooks; ssl_certificate .. /certs/4564529_jupyter.bioitee.com.pem; ssl_certificate_key .. /certs/4564529_jupyter.bioitee.com.key;
    ssl_ciphers "EECDH CHACHA20:EECDH CHACHA20-draft:EECDH AES128:RSA AES128:EECDH AES256:RSA AES256:EECDH 3DES:RSA 3DES:! MD5";
    ssl_protocols TLSv1 TLSv11. TLSv12.;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    location / {
        proxy_pass            http://jupyter;
        proxy_set_header      Host $host;
    }
    location ~ /api/kernels/ {
        proxy_pass            http://jupyter;
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }
    location ~ /terminals/ {
        proxy_pass            http://jupyter;
        proxy_set_header      Host $host;
        # websocket support
        proxy_http_version    1.1;
        proxy_set_header      Upgrade "websocket";
        proxy_set_header      Connection "Upgrade";
        proxy_read_timeout    86400;
    }

    access_log  logs/jupyterlab_acc.log;
    error_log   logs/jupyterlab_err.log;
}
Copy the code

5. Problems encountered

  1. Jupyter Lab startup process if used--config=~/.jupyter/jupyter_notebook_config.pyAs one of the startup parameters, it causes the other Conda environment to disappear on the Web side, leaving only a Python 3 Notebook and Console, for reasons not yet understood.
  2. jupyter lab --generate-configThe default generated configuration file is located~/.jupyter/jupyter_notebook_config.pyIt is not clear how to change the path to this default configuration file.

Read more

Someone poisoned the code! Use the PIP install command \ with caution

PIP 20.3 new release released! Getting rid of Python 2.x\

Quick mastery of scrapy crawler frame in 5 minutes

Special recommendation \

Programmer’s guide to fish

For your selection of Silicon Valley geeks,

From FLAG giant developers, technology, venture capital first-hand news

\

Click below to read the article and join the community