尝试在Centos7.6安装JupyterLab , 另外也可以直接使用Docker镜像安装。其依赖NodeJS和Python环境。另外尝试了Python2后发现部分插件已经不能支持了。因此安装时使用的是Python3.
1. 安装Nodejs
#[root@localhost ~]# cat /etc/redhat-release
#CentOS Linux release 7.6.1810 (Core)
yum install -y epel-release
# To install nodejs
curl -sL https://rpm.nodesource.com/setup_13.x | bash -
yum groupinstall -y 'development tools'
yum install -y nodejs
2. 安装yarn
## To install the Yarn package manager, run:
curl -sL https://dl.yarnpkg.com/rpm/yarn.repo | sudo tee /etc/yum.repos.d/yarn.repo
yum install -y yarn
# [root@localhost ~]# npm --version
# 6.12.0
# [root@localhost ~]# node --version
# v13.0.1
# [root@localhost ~]# yarn --version
# 1.19.1
3. 安装Python3和JupyterLab
yum install -y python3 python3-pip
# pip3 install jupyterlab
pip3 install --user jupyterlab
4. 配置和运行JupyterLab
firewall-cmd --permanent --zone=public --add-port=80/tcp
#firewall-cmd --permanent --zone=public --remove-port=80/tcp
firewall-cmd --reload && firewall-cmd --list-all
#[root@localhost ~]# jupyter --version
#jupyter core : 4.6.1
#jupyter-notebook : 6.0.1
#qtconsole : not installed
#ipython : 7.9.0
#ipykernel : 5.1.3
#jupyter client : 5.3.4
#jupyter lab : 1.1.4
#nbconvert : 5.6.1
#ipywidgets : not installed
#nbformat : 4.4.0
#traitlets : 4.3.3
# 使用密码访问,而不通过token访问
jupyter notebook --generate-config
jupyter notebook password
jupyter lab --ip=0.0.0.0 --port=80 --allow-root --no-browser
#http://127.0.0.1:80
生成密码配置路径在:/home/{username}/.jupyter/jupyter_notebook_config.json
, 内容结构可能如下:
{
"NotebookApp": {
"password": "sha1:0bb6084fe8be:28cced05d64537cfd9edf073f35e53535888ede2"
}
}
5. 可能引起安全问题
虽然直接使用方便,但是如果部署在外网服务器有一定风险,而且直接暴露SSH客户端。可以考虑HTTPS或者使用时内部通过SSH之类的本地转发。
a. 生成HTTPS证书和密钥
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout mycert.pem -out mycert.pem
b. 配置
如果前面已经生成密码,可以忽略下面密码的配置。
#/Users/you/.jupyter/jupyter_notebook_config.py
# Set options for certfile, ip, password, and toggle off
# browser auto-opening
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.keyfile = u'/absolute/path/to/your/certificate/mycert.pem'
# Set ip to '*' to bind on all interfaces (ips) for the public server
c.NotebookApp.ip = '*'
c.NotebookApp.password = u'sha1:bcd259ccf...<your hashed password here>'
c.NotebookApp.open_browser = False
# It is a good idea to set a known, fixed port for server access
c.NotebookApp.port = 9999
6.Ubuntu下安装
因为最新的1.7.0在加载nbclassic扩展时会有兼容问题。报错信息:
File "/usr/local/lib/python3.8/dist-packages/nbclassic/nbserver.py", line 80, in extensions
nb = self._extensions.get("nbclassic")
AttributeError: 'ExtensionManager' object has no attribute '_extensions'
这时使用建议的1.6.4版本
apt install nodejs python3-pip jupyter-core
pip3 install jupyterlab
pip3 install jupyter_server==1.6.4
pip3 install numpy pandas matplotlib statsmodels
7 测试功能
以下是网上代码:
import warnings
warnings.filterwarnings('ignore')
import pandas as pd
pd.options.display.max_rows=100
pd.options.display.max_columns=100
import matplotlib
%matplotlib inline
matplotlib.style.use('ggplot')
from matplotlib import pyplot as plt
import numpy as np
import statsmodels.api as sm
n=1024
X = np.random.normal(0, 1, n)
Y = np.random.normal(0, 1, n)
plt.figure(figsize=(15,8))
plt.scatter(X, Y, label = 'test')
plt.legend(loc='best')
绘制饼状图:
lables = [2,4,8,12,20,30,50,100]
values = [2238, 2242, 5938, 5967, 13394, 15837, 29645, 41319]
plt.figure(figsize=(12,12))
plt.pie(values, labels=lables,startangle=90, colors = ['red', 'gray', 'pink', 'brown', 'orange', 'yellow', 'green', 'blue'], autopct = '%3.1f%%')
plt.xlabel('downloadBW ' + "Mb/s")
plt.legend(loc='best')
评论 (0)