ipython中%load\u ext的工作方式
我安装软件包: 根据教程,我应该使用ipython中%load\u ext的工作方式,ipython,ipython-notebook,ipython-magic,Ipython,Ipython Notebook,Ipython Magic,我安装软件包: 根据教程,我应该使用 $ ipython In [1] : %load_ext ipydb 它看起来像是IPython的延伸 但是我感到困惑,这个软件包没有安装在我的“~/.ipython/extensions”下 所以,我想知道 %load\u ext magic是如何工作的,或者键入“%load\u ext ipydb”时发生了什么 如果我只键入“ipython”,它将使用默认配置文件,但在我的“~/.ipython/profile_default/”下没有配置文件,那么
$ ipython
In [1] : %load_ext ipydb
它看起来像是IPython的延伸
但是我感到困惑,这个软件包没有安装在我的“~/.ipython/extensions”下
所以,我想知道
- %load\u ext magic是如何工作的,或者键入“%load\u ext ipydb”时发生了什么
- 如果我只键入“ipython”,它将使用默认配置文件,但在我的“~/.ipython/profile_default/”下没有配置文件,那么ipython如何进行配置
aaron@aarons-MacBook-Pro:~/Desktop/github/ipydb$ls ~/.ipython/profile_default/
db history.sqlite log nbconfig pid security startup static
aaron@aarons-MacBook-Pro:~/Desktop/github/ipydb$ipython profile create my_profile
[ProfileCreate] Generating default config file: u'/Users/aaron/.ipython/profile_my_profile/ipython_config.py'
[ProfileCreate] Generating default config file: u'/Users/aaron/.ipython/profile_my_profile/ipython_kernel_config.py'
[ProfileCreate] Generating default config file: u'/Users/aaron/.ipython/profile_my_profile/ipython_console_config.py'
[ProfileCreate] Generating default config file: u'/Users/aaron/.ipython/profile_my_profile/ipython_qtconsole_config.py'
[ProfileCreate] Generating default config file: u'/Users/aaron/.ipython/profile_my_profile/ipython_notebook_config.py'
[ProfileCreate] Generating default config file: u'/Users/aaron/.ipython/profile_my_profile/ipython_nbconvert_config.py'
aaron@aarons-MacBook-Pro:~/Desktop/github/ipydb$ls ~/.ipython/profile_my_profile/
ipython_config.py ipython_nbconvert_config.py log startup
ipython_console_config.py ipython_notebook_config.py pid static
ipython_kernel_config.py ipython_qtconsole_config.py security
aaron@aarons-MacBook-Pro:~/Desktop/github/ipydb$
谢谢,好的,最后,我找到了在ipython中加载扩展的逻辑: 源代码位于: 核心逻辑是:
def load_extension(self, module_str):
"""Load an IPython extension by its module name.
Returns the string "already loaded" if the extension is already loaded,
"no load function" if the module doesn't have a load_ipython_extension
function, or None if it succeeded.
"""
if module_str in self.loaded:
return "already loaded"
from IPython.utils.syspathcontext import prepended_to_syspath
with self.shell.builtin_trap:
if module_str not in sys.modules:
with prepended_to_syspath(self.ipython_extension_dir):
__import__(module_str)
mod = sys.modules[module_str]
if self._call_load_ipython_extension(mod):
self.loaded.add(module_str)
else:
return "no load function"
这是有意义的现在,感谢IPython团队建立这样一个优秀的工具,我真的很喜欢它
def load_extension(self, module_str):
"""Load an IPython extension by its module name.
Returns the string "already loaded" if the extension is already loaded,
"no load function" if the module doesn't have a load_ipython_extension
function, or None if it succeeded.
"""
if module_str in self.loaded:
return "already loaded"
from IPython.utils.syspathcontext import prepended_to_syspath
with self.shell.builtin_trap:
if module_str not in sys.modules:
with prepended_to_syspath(self.ipython_extension_dir):
__import__(module_str)
mod = sys.modules[module_str]
if self._call_load_ipython_extension(mod):
self.loaded.add(module_str)
else:
return "no load function"