jupyterlab局域网使用

简单的 jupyter lab 局域网使用配置

个人电脑状态:防火墙关闭

安装

https://jupyter.org/install

pip install jupyterlab

生成配置文件

jupyter lab --generate-config

打开配置文件,默认在~/.jupyter/jupyter_lab_config.py

修改配置文件

c.ServerApp.ip = '0.0.0.0'           # 监听所有网卡,局域网其他设备才能访问
c.ServerApp.port = 8888              # 端口号,默认8888
c.ServerApp.open_browser = False     # 不自动打开浏览器
c.ServerApp.allow_remote_access = True  # 允许远程访问

设置密码,否则无法登录

jupyter lab password

启动 jupyter lab

jupyter lab

在另一台计算机上打开:

http://your_ip:8888

输入密码即可进入

其他

安装模块

pip install matplotlib numpy

测试

import numpy as np
import matplotlib.pyplot as plt

# 创建x轴的数据,从 -2π 到 2π,间隔为0.01
x = np.linspace(-2 * np.pi, 2 * np.pi, 1000)

# 计算y轴的sin(x)
y = np.sin(x)

# 绘图
plt.figure(figsize=(10, 5))
plt.plot(x, y, label='sin(x)', color='blue')
plt.axhline(0, color='black', linewidth=0.5)  # x轴
plt.axvline(0, color='black', linewidth=0.5)  # y轴
plt.title('正弦函数曲线 sin(x)')
plt.xlabel('x')
plt.ylabel('sin(x)')
plt.grid(True)
plt.legend()
plt.show()

comment: