jupyterlab安装配置

介绍

Jupyter源于Ipython Notebook,是使用Python(也有R、Julia、Node等其他语言的内核)进行代码演示、数据分析、可视化、教学的很好的工具,对Python的愈加流行和在AI领域的领导地位有很大的推动作用。

Jupyter Lab是Jupyter的一个拓展,提供了更好的用户体验,例如可以同时在一个浏览器页面打开编辑多个Notebook,Ipython console和terminal终端,并且支持预览和编辑更多种类的文件,如代码文件,Markdown文档,json,yml,csv,各种格式的图片,vega文件(一种使用json定义图表的语言)和geojson(用json表示地理对象),还可以使用Jupyter Lab连接Google Drive等云存储服务,极大得提升了生产力。

安装

1
pip install jupyterlab

安装扩展

1
2
3
4
5
6
pip install jupyter-nbextensions-configurator

# github
jupyter labextension install @jupyterlab/github

# 更多插件: https://github.com/jupyterlab

初始化jupyter note配置文件

1
2
3
4
5
6
7
# 配置文件目录~/.jupyter

jupyter notebook --generate-config

c.NotebookApp.notebook_dir = u'/home/wuyue/jupyterlab'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:86529cd5e164:77885f708db4abeace06733f9b7a7caaa2447651'

密码生成

1
jupyter-notebook password

jupyterlab 添加 kernel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 以虚拟环境微粒
# 1. python3

pyenv shell python36
pip install ipykernel
python -m ipykernel install –user

# 2. python2

pyenv shell python27
# ipython6.x不再支持python2
pip install ipython==5.0.0
pip install ipykernel
python -m ipykernel install –user

Nginx配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
server {
listen 80;
server_name jupyterlab.xxx.com;
return 301 https://$server_name$request_uri;
}

server {
# the port your site will be served on
listen 443 ssl;
server_name jupyterlab.xxx.com;

# the domain name it will serve for
charset utf-8;

ssl_certificate /etc/nginx/cert/jupyterlab/full_chain.pem;
ssl_certificate_key /etc/nginx/cert/jupyterlab/private.key;
ssl_session_timeout 5m;
ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_prefer_server_ciphers on;

access_log /data/logs/nginx/jupyterlab/access_log;
error_log /data/logs/nginx/jupyterlab/error_log;

# max upload size
client_max_body_size 75M; # adjust to taste
location / {
proxy_pass http://localhost:8888;
proxy_set_header Host $host;
}
location ~* /lab|(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/? {
proxy_pass http://localhost:8888;
proxy_set_header HOST $host;
# websocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
}
}