Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
IPython:启动时自动加载扩展_Ipython - Fatal编程技术网

IPython:启动时自动加载扩展

IPython:启动时自动加载扩展,ipython,Ipython,在IPython中,我可以使用以下简单命令加载自定义扩展: %load_ext physics %load_ext physics 这将加载文件~/.ipython/extensions/physics.py 如何让IPython在启动时自动加载扩展 我已将该行添加到/.ipython/profile\u default/startup/import.py,但这不起作用: from numpy import * %load_ext physics 启动IPython时,出现以下错误: F

在IPython中,我可以使用以下简单命令加载自定义扩展:

%load_ext physics
%load_ext physics
这将加载文件
~/.ipython/extensions/physics.py

如何让IPython在启动时自动加载扩展

我已将该行添加到
/.ipython/profile\u default/startup/import.py
,但这不起作用:

from numpy import *

%load_ext physics
启动IPython时,出现以下错误:

File "~/.ipython/profile_default/startup/import.py", line 17
%load_ext physics
^
SyntaxError: invalid syntax
从:

使用扩展功能

要在IPython运行时加载扩展,请使用
%load\u ext
magic:

In [1]: %load_ext myextension
要在每次IPython启动时加载它,请在配置文件中列出它:

c.InteractiveShellApp.extensions = [
    'myextension'
]

希望这有助于

我确认您最初尝试的,但使用
.ipy
启动文件也可以工作:

$ cat ~/.ipython/profile_default/startup/load_extensions.py
get_ipython().run_line_magic('load_ext', 'autoreload')
~/.ipython/profile\u default/startup/physics.ipy