安装 Jupyter 扩展 - 从 setup.py 开始自动安装和启用
Installation of Jupyter Extensions - Automatic installation and enabling from setup.py
我正在尝试自动安装和启用 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/
.
中复制了整个 <my_fancy_module>
根据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
- 我应该指定什么 directory
才能成功安装和启用 my_fancy_module
?
我试过了:
"/Library/Jupyter/nbextensions/my_fancy_module"
、"../Library/Jupyter/nbextensions/my_fancy_module"
、"share/jupyter/nbextensions/my_fancy_module"
但其中 none 有效。
似乎 data_files
很难接受 绝对路径 作为 目的地 ,但是如果你 运行 setup.py
带有 --no-binary
标志,即 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']))]
...
)
我正在尝试自动安装和启用 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/
.
<my_fancy_module>
根据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’ssys.prefix
for system installations;site.USER_BASE
for user installations).
我的 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"
但其中 none 有效。
似乎 data_files
很难接受 绝对路径 作为 目的地 ,但是如果你 运行 setup.py
带有 --no-binary
标志,即 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']))]
...
)