jupyter 服务端扩展开发

1、项目结构
复制代码
jupyter_code/
├── jupyter_code/
│   ├── __init__.py      # 修复后的代码
│   ├── handlers.py      # 修复后的代码
│   └── __pycache__/
├── setup.py             # 修复后的代码
├── MANIFEST.in          # (可选)包含额外文件
├── README.md            # (可选)文档
├── test_extension.py    # 测试脚本(没有做)
└── verify_extension.py  # 验证脚本(没有做)

# setup.py
from setuptools import setup

setup(
    name="jupyter_code",
    version="0.1.0",
    packages=["jupyter_code"],
    install_requires=["jupyterlab", "tornado"],
    entry_points={
        "jupyter_server_extension": [
            "jupyter_code = jupyter_code"
        ]
    },
)

# __init__.py
from .handlers import HelloWorldHandler


def load_jupyter_server_extension(server_app):
    """用于加载Jupyter服务器扩展的函数。"""
    handlers = [
        (r"/jupyter_code/hello", HelloWorldHandler)
    ]
    server_app.web_app.add_handlers(".*$", handlers)
    server_app.log.info("jupyter_code 扩展已加载")

# handlers.py
from jupyter_server.base.handlers import APIHandler
from tornado import web


class HelloWorldHandler(APIHandler):
    @web.authenticated
    def get(self):
        self.finish("Hello, world!")
2、然后打包安装。
复制代码
python setup.py  bdist_wheel

pip install dist\jupyter_code-0.0.1-py3-none-any.whl

网上的注册扩展做法

复制代码
jupyter server extension enable jupyter_code

测试后发现不起作用

3. 手动配置扩展

如果扩展已安装但未自动注册,可以手动配置:

A. 创建配置文件
复制代码
# 生成默认配置文件(如果不存在)
jupyter server --generate-config

# 编辑配置文件
vim ~/.jupyter/jupyter_server_config.py
B. 添加扩展配置
复制代码
# 在 jupyter_server_config.py 中添加
c.ServerApp.jpserver_extensions = {
    'jupyter_code': True,

}
相关推荐
Groundwork Explorer35 分钟前
W5500 网卡编程初始化与使用指南
python·单片机
逸Y 仙X1 小时前
MCP(模型控制协议)完全指南:从核心概念到实战开发
python·大模型·llm·ai编程·mcp
WILLF2 小时前
前端视角:Python requests vs JS axios
前端·python
哒哒哒5285202 小时前
69. Python: 核心语法-面向对象基础-案例(教务系统)
python
何以解忧,唯有..2 小时前
Python 中获取目录操作完全指南
windows·python·microsoft
南京云森杉木桩2 小时前
常见打桩木品牌推荐,选对材质让工程更稳固
人工智能·python·材质
总有刁民想爱朕ha2 小时前
Python PyQt5图片批量转MP4视频工具:本地离线免费无水印,完整代码
开发语言·python·qt
zyj8890912 小时前
濮阳工厂目视化设计安全警示牌材质怎么选耐用
python·安全·材质
宸津-代码粉碎机3 小时前
FastUtil+AI多Agent实战:Java AI项目性能终极加速方案
java·服务器·开发语言·python·安全·php
for_ever_love__3 小时前
python基础语法学习: 装饰器
python·学习·装饰器·装饰器模式