简体   繁体   English

在IPython启动时自动加载模块

[英]Auto-Loading a module on IPython startup

I'm trying to to auto load the division module from __future__ on startup, i've currently got a simple script in the IPython startup libray with the line: 我试图在启动时从__future__自动加载division模块,我目前在IPython启动库中有一个简单的脚本,其内容如下:

from __future__ import division

which works fine when run directly from the shell, however, the module does not appear to load when the line is run from the script, i made sure that the startup script is loaded by adding some arbitrary variable assignments to it: 直接从外壳运行时可以正常工作,但是从脚本运行该行时,该模块似乎没有加载,我通过向其添加一些任意变量分配来确保已加载启动脚本:

from __future__import division
x=1
y=2

and the variables were preassigned when IPython was launched (as expected). 并在启动IPython时(如预期的那样)预先分配了变量。

I've tried looking at some solutions here and here but got nowhere, any help would be appreciated, thanks 我试图在这里这里寻找一些解决方案,但无济于事,任何帮助将不胜感激,谢谢

i've found a solution to this one, in your IPython profile directory (by default - .ipython\\profile_default ), edit the file ipython_config.py (create it with ipython profile create if it does not exist) with the following lines: 我找到了一个解决方案,在您的IPython配置文件目录(默认为.ipython\\profile_default )中,用以下几行编辑文件ipython_config.py (如果不存在,请使用ipython profile create ):

# loads the root config object
c=get_config()

# executes the line in brackets on program launch
c.InteractiveShellApp.exec_lines = ['from __future__ import division']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM