安装Jupyter Extensions自动安装和启用设置.py

2024-05-29 11:24:37 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试自动安装和启用Jupyter扩展,这样用户就不需要键入命令:

jupyter nbextension install --user <my_fancy_module>
jupyter nbextension enable <the entry point> --user

Jupyter Notebook documentation中所述,可以在setup.py中指定:

import setuptools

setuptools.setup(
    name="MyFancyModule",
    ...
    include_package_data=True,
    data_files=[
        # like `jupyter nbextension install --sys-prefix`
        ("share/jupyter/nbextensions/my_fancy_module", [
            "my_fancy_module/static/index.js",
        ]),
        # like `jupyter nbextension enable --sys-prefix`
        ("etc/jupyter/nbconfig/notebook.d", [
            "jupyter-config/nbconfig/notebook.d/my_fancy_module.json"
        ])
    ],
    ...
    zip_safe=False
)

但是,当我尝试在包目录中运行pip install .时,安装完成,但my_fancy_module没有安装。跑步:

jupyter nbextension install --user <my_fancy_module>

工作正常,因为它正确地复制了<my_fancy_module>中我的包目录中的整个~/Library/Jupyter/nbextensions/。你知道吗

根据Python documentation on Installing Additional Files

data_files specifies a sequence of (directory, files) (...) Each (directory, files) pair in the sequence specifies the installation directory and the files to install there. (...) The directory should be a relative path. It is interpreted relative to the installation prefix (Python’s sys.prefix for system installations; site.USER_BASE for user installations).

我的site.USER_BASE指向~/.local。你知道吗

我的问题是:

如何从setup.py内部安装并启用my_fancy_package,从而得到与执行开头提到的两个命令相同的结果?如果这是关于指定data_files-为了成功安装和启用my_fancy_module,我应该指定什么directory?你知道吗

我试过:

"/Library/Jupyter/nbextensions/my_fancy_module""../Library/Jupyter/nbextensions/my_fancy_module""share/jupyter/nbextensions/my_fancy_module"

但都没用。你知道吗


Tags: installthedataprefixmysetupjupyterfiles
1条回答
网友
1楼 · 发布于 2024-05-29 11:24:37

似乎data_files很难接受绝对路径作为目的地,但是如果您使用 no-binary标志运行setup.py,即pip install <my_package> no-binary :all":,它可以正常工作。你知道吗

from os import path
setuptools.setup(
    ...
    data_files=[((path.expanduser('~') + '/Library/Jupyter/nbextensions/my_fancy_module', 
                  ['my_fancy_module/static/index.js']))]
    ...
)

相关问题 更多 >

    热门问题