除非置于常规配置文件中,否则将忽略ipython笔记本配置选项

时间:2015-04-15 14:57:37

标签: macos ipython-notebook

OS X 10.6.8,ipython从1.something(从fink)升级到3.0.0(使用pip)。除了配置问题外,一切似乎都能正常工作。

从文档和我自己的测试中,我无法理解.ipython/profile_default/ipython_config.pyipython_notebook_config.py中配置选项的预期行为。

我想为我的笔记本自动加载几个扩展和模块,但不是我的常规ipython会话(部分是因为这些加载会产生警告,但似乎我应该能够将这些配置分开)。似乎有意义的是,仅适用于笔记本的配置选项会进入笔记本配置。但是当我把选项放在ipython_config.py中时,我只能让笔记本能够尊重我的选择。它似乎忽略了笔记本配置,而且我仍然坚持非笔记本ipython也加载这些模块。难道我做错了什么?

文档没有明确说明区别,这些文件中的内联注释没有引用这两个配置文件之间的区别,只是从Application和InteractiveShellApp继承TerminalIPythonApp(但两个配置文件中的类名相同) )。笔记本配置阅读的规则是什么? ipython首先从一个读取,然后是另一个读取吗?目前,它似乎完全忽略了ipython_notebook_config.py,为什么它在那里呢?

从2013年开始可能与此相关:http://mail.scipy.org/pipermail/ipython-user/2013-February/012170.html 但是解决他的问题的提交肯定是在这一点的主回购中,所以也许不是......

ipython notebook --debug的结果是

[D 10:37:52.595 NotebookApp] Config changed:
[D 10:37:52.595 NotebookApp] {'NotebookApp': {'log_level': 10}}
[D 10:37:52.596 NotebookApp] IPYTHONDIR set to: /Users/robclewley/.ipython
[I 10:37:52.598 NotebookApp] Using existing profile dir: u'/Users/robclewley/.ipython/profile_default'
[D 10:37:52.598 NotebookApp] Searching path [u'/Users/robclewley/Work/literate_modeling/scenario-local-linear/notebook/project', u'/Users/robclewley/.ipython/profile_default', '/usr/local/etc/ipython', '/etc/ipython'] for config files
[D 10:37:52.598 NotebookApp] Attempting to load config file: ipython_config.py
[D 10:37:52.600 NotebookApp] Loaded config file: /Users/robclewley/.ipython/profile_default/ipython_config.py
[D 10:37:52.601 NotebookApp] Config changed:
[D 10:37:52.601 NotebookApp] {'TerminalInteractiveShell': {'logstart': True}, 'NotebookApp': {'log_level': 10}, 'TerminalIPythonApp': {'matplotlib': 'osx'}}
[D 10:37:52.602 NotebookApp] Attempting to load config file: ipython_notebook_config.py
[D 10:37:52.604 NotebookApp] Loaded config file: /Users/robclewley/.ipython/profile_default/ipython_notebook_config.py
[D 10:37:52.605 NotebookApp] Config changed:
[D 10:37:52.605 NotebookApp] {'TerminalInteractiveShell': {'logstart': True}, 'NotebookApp': {'log_level': 10}, 'InteractiveShellApp': {'exec_lines': ['import notebook_importing'], 'gui': 'osx', 'pylab': 'osx', 'matplotlib': 'osx', 'extensions': ['yaml_magic', 'autoreload'], 'extra_extension': 'yaml_magic'}, 'TerminalIPythonApp': {'extra_extension': 'yaml_magic', 'extensions': ['yaml_magic'], 'matplotlib': 'osx'}}
[D 10:37:52.611 NotebookApp] searching for local mathjax in [u'/Users/robclewley/.ipython/nbextensions', '/sw/share/jupyter/nbextensions', '/usr/local/share/jupyter/nbextensions', '/usr/share/jupyter/nbextensions']
[D 10:37:52.613 NotebookApp] searching for local mathjax in [u'/Users/robclewley/.ipython/profile_default/static', '/sw/lib/python2.7/site-packages/IPython/html/static']
[I 10:37:52.613 NotebookApp] Using MathJax from CDN: https://cdn.mathjax.org/mathjax/latest/MathJax.js

例如,在笔记本中调用magic命令%% yaml(来自我的自定义扩展名)会导致投诉该命令无法识别。相反,如果我将这些扩展设置为在ipython_config.py中加载,那么笔记本会立即接受%% yaml。在这种情况下,调试输出为:

[D 10:46:50.330 NotebookApp] Config changed:
[D 10:46:50.330 NotebookApp] {'NotebookApp': {'log_level': 10}}
[D 10:46:50.331 NotebookApp] IPYTHONDIR set to: /Users/robclewley/.ipython
[I 10:46:50.332 NotebookApp] Using existing profile dir: u'/Users/robclewley/.ipython/profile_default'
[D 10:46:50.332 NotebookApp] Searching path [u'/Users/robclewley/Work/literate_modeling/scenario-local-linear/notebook/project', u'/Users/robclewley/.ipython/profile_default', '/usr/local/etc/ipython', '/etc/ipython'] for config files
[D 10:46:50.332 NotebookApp] Attempting to load config file: ipython_config.py
[D 10:46:50.335 NotebookApp] Loaded config file: /Users/robclewley/.ipython/profile_default/ipython_config.py
[D 10:46:50.336 NotebookApp] Config changed:
[D 10:46:50.337 NotebookApp] {'TerminalInteractiveShell': {'logstart': True}, 'NotebookApp': {'log_level': 10}, 'InteractiveShellApp': {'extensions': ['yaml_magic', 'autoreload']}, 'TerminalIPythonApp': {'matplotlib': 'osx'}}
[D 10:46:50.337 NotebookApp] Attempting to load config file: ipython_notebook_config.py
[D 10:46:50.338 NotebookApp] Loaded config file: /Users/robclewley/.ipython/profile_default/ipython_notebook_config.py
[D 10:46:50.339 NotebookApp] Config changed:
[D 10:46:50.340 NotebookApp] {'TerminalInteractiveShell': {'logstart': True}, 'NotebookApp': {'log_level': 10}, 'InteractiveShellApp': {'extra_extension': 'yaml_magic', 'extensions': ['yaml_magic', 'autoreload'], 'exec_lines': ['import notebook_importing'], 'gui': 'osx', 'pylab': 'osx', 'matplotlib': 'osx'}, 'TerminalIPythonApp': {'extra_extension': 'yaml_magic', 'extensions': ['yaml_magic'], 'matplotlib': 'osx'}}
[D 10:46:50.345 NotebookApp] searching for local mathjax in [u'/Users/robclewley/.ipython/nbextensions', '/sw/share/jupyter/nbextensions', '/usr/local/share/jupyter/nbextensions', '/usr/share/jupyter/nbextensions']
[D 10:46:50.345 NotebookApp] searching for local mathjax in [u'/Users/robclewley/.ipython/profile_default/static', '/sw/lib/python2.7/site-packages/IPython/html/static']

感谢。

1 个答案:

答案 0 :(得分:0)

与此同时,这里得到了回答: http://comments.gmane.org/gmane.comp.python.ipython.user/11941

基本上,内核和笔记本服务器是不同的。内核的配置文件(在我的系统上默认缺失)是根,全局配置选项所在的位置。从论坛帖子中,有关此结构的更清晰的文档即将发布。