如何从 Jupyter 4.x 获取 IPython 配置文件行为? [英] How do I get IPython profile behavior from Jupyter 4.x?
问题描述
官方(?)建议运行 IPython Notebook 服务器,并通过
There was official(?) recommendation of running an IPython Notebook server, and creating a profile via
$ ipython profile create nbserver
按照 http://ipython.org/ipython-doc/1 中的推荐/interactive/public_server.html.这允许在通过 ipython notebook
和 ipython notebook --profile=nbserver
启动 IPython Notebook 时出现非常不同且非常有用的行为.
as recommended in http://ipython.org/ipython-doc/1/interactive/public_server.html. This allowed for very different and very useful behavior when starting an IPython Notebook via ipython notebook
and ipython notebook --profile=nbserver
.
在 Jupyter 4.0 中,发生了变化,不再有配置文件.我找到了对话 https://gitter.im/ipython/ipython/archives/2015/05/29 其中有用户 minrk 说:
With Jupyter 4.0, there's a change and there are no longer profiles. I've found the conversation https://gitter.im/ipython/ipython/archives/2015/05/29 which has user minrk saying:
.ipython 目录中有几样东西:
The .ipython directory has several things in it:
多个配置目录(称为配置文件)
multiple config directories (called profiles)
一个 'data' 目录,包含诸如 kernelspecs、nbextensions 之类的内容
one 'data' directory, containing things like kernelspecs, nbextensions
运行时信息分散在各处,但主要在配置文件中
runtime info scattered throughout, but mostly in profiles
Jupyter 遵循更适合平台的约定:
Jupyter follows more platform-appropriate conventions:
JUPYTER_CONFIG_DIR 的一个配置目录,默认:.jupyter
one config dir at JUPYTER_CONFIG_DIR, default: .jupyter
JUPYTER_DATA_DIR 的一个数据目录,默认:特定于平台
one data dir at JUPYTER_DATA_DIR, default: platform-specific
一个运行时目录位于 JUPYTER_RUNTIME_DIR,默认:特定于平台
one runtime dir at JUPYTER_RUNTIME_DIR, default: platform-specific
还有一个相当隐晦的评论:
And a rather cryptic remark:
如果您想使用不同的配置,请使用 JUPYTER_CONFIG_DIR=whatever 指定不同的配置目录
If you want to use different config, specify a different config directory with JUPYTER_CONFIG_DIR=whatever
获得不同行为的最佳方法是什么(例如,作为服务器运行与正常使用之间)?
What's the best way to get different behavior (say, between when running as a server vs normal usage)?
它是否涉及运行类似的东西:
Will it involve running something like:
$ export JUPYTER_CONFIG_DIR=~/.jupyter-nbserver
$ jupyter notebook
何时需要运行服务器配置文件"?和
whenever a server 'profile' needs to be run? and
$ export JUPYTER_CONFIG_DIR=~/.jupyter
$ jupyter notebook
何时需要运行正常"配置文件?因为那看起来很可怕.在 Jupyter 4.0 中执行此操作的最佳方法是什么?
whenever a 'normal' profile needs to run? Because that seems terrible. What's the best way to do this in Jupyter 4.0?
推荐答案
使用这篇博文中的一些代码 http://www.svds.com/jupyter-notebook-best-practices-for-data-science/ 并更新它.最简单的解决方案似乎是创建一个别名,例如:
Using some code from this blog post http://www.svds.com/jupyter-notebook-best-practices-for-data-science/ and updating it. The easiest solution appears to be to create an alias, like:
alias jupyter-nbserver='JUPYTER_CONFIG_DIR=~/.jupyter-nbserver jupyter notebook'
所以现在您可以通过简单的命令 jupyter-nbserver
使用不同的配置运行 jupyter notebook.
So now you can run the jupyter notebook with a different config via the simple command jupyter-nbserver
.
更强大的解决方案可能涉及创建一个更改环境变量的 bash 函数,检查是否有配置文件,如果没有创建,则执行,但这可能有点过头了.我在这个相关问题上给出的答案 https://stackoverflow.com/a/32516200/246856 用于创建新配置文件"的初始配置文件.
A more robust solution might involve creating a bash function that changes the environment variable, checks whether there's a config file, if not creating one, then executing, but that's probably overkill. The answer that I give on this related question https://stackoverflow.com/a/32516200/246856 goes into creating the initial config files for a new 'profile'.
这篇关于如何从 Jupyter 4.x 获取 IPython 配置文件行为?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!