【问题标题】:Installation of Jupyter Extensions - Automatic installation and enabling from setup.py安装 Jupyter 扩展 - 从 setup.py 自动安装和启用
【发布时间】:2020-01-29 02:23:23
【问题描述】:

我正在尝试自动安装和启用 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>

效果很好,因为它正确地从 ~/Library/Jupyter/nbextensions/ 内的我的包目录中复制了整个 &lt;my_fancy_module&gt;

根据Python documentation on Installing Additional Files

data_files 指定(目录、文件)(...)序列中的每个(目录、文件)对指定安装目录和要安装在那里的文件。 (...) 目录应该是相对路径。它相对于安装前缀进行解释(Python 的 sys.prefix 用于系统安装;site.USER_BASE 用于用户安装)。

我的site.USER_BASE 指向~/.local

我的问题是:

如何从setup.py 内部安装和启用my_fancy_package,以便最终得到与执行开头提到的两个命令相同的结果?如果这是关于指定data_files - 我应该指定什么directory 才能成功安装和启用my_fancy_module

我试过了:

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

但它们都不起作用。

【问题讨论】:

    标签: python pip jupyter-notebook jupyter setuptools


    【解决方案1】:

    似乎data_files 难以接受绝对路径 作为目的地,但如果您使用--no-binary 标志运行setup.py,即pip install &lt;my_package&gt; --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']))]
        ...
    )
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-01
      • 2021-01-10
      • 1970-01-01
      • 2021-06-07
      相关资源
      最近更新 更多