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

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

问题描述

我试图在启动时从 __future__ 自动加载 division 模块,我目前在 IPython 启动库中有一个简单的脚本:

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 运行时效果很好,但是,当从脚本运行该行时,该模块似乎没有加载,我确保通过向其中添加一些任意变量赋值来加载启动脚本:

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 配置文件目录(默认 - .ipythonprofile_default)中,编辑文件 ipython_config.py(如果它不存在,则使用 ipython profile create 创建它)包含以下几行:

i've found a solution to this one, in your IPython profile directory (by default - .ipythonprofile_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天全站免登陆