要搭建本地网络用户的JupyterHub,可以按照以下步骤进行操作:
安装JupyterHub和所需的依赖项:
pip install jupyterhub
生成JupyterHub的配置文件:
jupyterhub --generate-config
打开生成的配置文件 jupyterhub_config.py
,并进行以下修改:
c.JupyterHub.ip = '0.0.0.0'
c.JupyterHub.port = 8000
from jupyter_client.localinterfaces import public_ips
c.JupyterHub.authenticator_class = 'jupyterhub.auth.PAMAuthenticator'
c.JupyterHub.spawner_class = 'jupyterhub.spawner.LocalProcessSpawner'
c.Spawner.notebook_dir = '~/notebooks'
保存配置文件,并启动JupyterHub服务器:
jupyterhub
现在,您可以通过浏览器访问 http://服务器IP地址:8000
来访问JupyterHub。
示例代码:
import matplotlib.pyplot as plt
import numpy as np
# 生成随机数据
x = np.linspace(0, 2 * np.pi, 100)
y = np.sin(x)
# 绘制图形
plt.plot(x, y)
plt.xlabel('x')
plt.ylabel('y')
plt.title('Sin Wave')
plt.show()
这是一个简单的绘制正弦波的示例,您可以在Jupyter Notebook中运行该代码并查看结果。