在IPython启动时自动加载模块 [英] Auto-Loading a module on IPython startup

查看:280
本文介绍了在IPython启动时自动加载模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在启动时从 __ future __ 自动加载部门模块,
i目前在IPython初创公司的libray中有一个简单的脚本:

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:

from __future__ import division

直接从shell运行时工作正常,
但是,当该行模块时,该模块似乎没有加载从脚本运行,
i确保通过向其添加一些任意变量赋值来加载启动脚本:

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

并且变量已预先分配IPython推出(正如预期的那样)。

and the variables were preassigned when IPython was launched (as expected).

我试过看一些解决方案此处这里但无处可去,
任何帮助都会受到赞赏,
谢谢

I've tried looking at some solutions here and here but got nowhere, any help would be appreciated, thanks

推荐答案

我已经在您的IPython配置文件目录中找到了这个解决方案(默认情况下为 .ipython \profile_default ),编辑文件 ipython_config.py (使用 ipython profile create 创建它,如果它不存在),并带有以下行: / p>

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:

# loads the root config object
c=get_config()

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

这篇关于在IPython启动时自动加载模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆