如何安装和启用Jupyter扩展使其具有可复制性? [英] How should Jupyter extensions be installed and enabled for being reproducible?

查看:137
本文介绍了如何安装和启用Jupyter扩展使其具有可复制性?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用 RISE制作交互式幻灯片集(用于使用python进行实时编码的演示文稿) aka live_reveal,它是Jupyter的笔记本扩展.

我希望幻灯片集可以供其他人(以及将来的自己)使用,而无需过多的手动步骤(并且不依赖于托管的Jupyter解决方案),因此,我选择了pipenv来管理依赖项. /p>

我可以开始使用

 pipenv install RISE
pipenv run jupyter nbextension install rise --py --sys-prefix
pipenv run jupyter nbextension enable rise --py --sys-prefix
pipenv run jupyter notebook  # to start the jupyter server
 

但是,只有pipenv install RISE将痕迹留在本地目录中(在PipfilePipfile.lock中).因此,当在新计算机上(或pipenv --rm之后)使用我的文件时,

pipenv install
pipenv run jupyter notebook

不够. 必须重复执行两个nbextension步骤,以启用RISE扩展,并在Jupyter笔记本电脑中使用该按钮以切换到演示模式.

这可以自动化吗?(不使用使用诸如conda,docker,vagrant,make或其他构建系统之类的其他工具,...)如果是这样,应该怎么做?自动化吗?

我可以告诉pipenv(例如在Pipfile中)在安装软件包后运行这两个命令吗?还是应该让笔记本(*.ipynb文件)以某种方式加载扩展名?

解决方案

这超出了pipenv的范围. Pipenv管理您的 python 环境-即安装了哪些软件包-实际上仅此而已. (对此的一个例外是,在pipenv runpipenv shell命令中加载了.env文件中的环境变量).您在问题中列出的nbextension命令实际上根本没有处理python环境,而是在(install rise)周围移动javascript和css文件并创建(或编辑(如果已安装其他nbextensions的话))json配置文件( enable rise).

不管是好是坏,pipenv都没有像postinstall钩子这样的东西来运行任意构建命令. jupyter似乎也没有预打包或自动安装扩展的方法,尽管我对此可能是错的.

我个人认为使这种事情可重复是您提到的构建工具最适合的.最好不要使用您不希望使用的那种构建工具,最好是编写清晰的自述文件,或者编写自己的(记录在案)安装后shell脚本.

I'd like to make interactive slide set (for a presentation with some live coding in python) with RISE a.k.a. live_reveal, which is a notebook extension for Jupyter.

I'd like the slide set to be usable by others (and by my future self) without too many manual steps (and without relying on hosted Jupyter solutions), thus I've chosen pipenv to manage dependencies.

I can get started with

pipenv install RISE
pipenv run jupyter nbextension install rise --py --sys-prefix
pipenv run jupyter nbextension enable rise --py --sys-prefix
pipenv run jupyter notebook  # to start the jupyter server

However, only pipenv install RISE leaves traces in the local directory (in Pipfile and Pipfile.lock). So, when using my files on a new machine (or after pipenv --rm) just

pipenv install
pipenv run jupyter notebook

won't suffice. The two nbextension steps will have to be repeated to enable the RISE extension and have the button available in Jupyter notebooks to switch to presentation mode.

Can this be automated? (Without employing additional tools like conda, docker, vagrant, make or other build systems, ...) If so, how should it be automated?

Can I tell pipenv (e.g. in Pipfile) to run these two commands after package installation? Or should I let the notebook (the *.ipynb file) load the extensions somehow?

解决方案

This is out of scope for pipenv. Pipenv manages your python environment - i.e., which packages are installed - and really nothing more. (The one exception to this is that environment variables in a .env file are loaded on pipenv run or pipenv shell commands). The nbextension commands you listed in your question are actually not dealing with the python environment at all, but are moving javascript and css files around (install rise) and creating (or editing, if you had other nbextensions installed) a json config file (enable rise).

For better or for worse, pipenv does not have anything like a postinstall hook for running arbitrary build commands. Nor does jupyter seem to have a way to prepackage or automatically install extensions, although I may be wrong about that.

My personal opinion is that making this sort of thing repeatable is exactly what the build tools you mentioned are great for. Your best bet without using a build tools of the sort you mentioned you would rather not use is to write a clear readme or maybe your own (documented) postinstall shell script.

这篇关于如何安装和启用Jupyter扩展使其具有可复制性?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆