如何在IPython中自动设置默认路径 [英] How to set default path automatically in IPython

查看:657
本文介绍了如何在IPython中自动设置默认路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用WingIDE进行开发,使用Ipython运行脚本。我在几点上面临一些不便:

I'm using WingIDE for development and Ipython for running my scripts. I'm facing some inconvenience on several points:

  • Whenever I update my code, I have to reload my module in order to update it in IPython. To solve that I followed Jomonsugi's answer in the following link: How to automatically reload modules in IPython? and it works.

每次启动IPython时,我的路径都设置为我的exe位置,我必须cd到我的脚本目录。
我试图通过在 ipython_config.py中设置参数 c.InteractiveShell.ipython_dir =< mypath> 来启动IPython时自动更改目录但它不起作用。

Each time I launch IPython, my path is set to my exe's location and I have to cd to my script's directory. I tried to change directory automatically when launching IPython by setting the parameter c.InteractiveShell.ipython_dir = <mypath> in ipython_config.py but it doesn't work.

是否可以设置默认路径?是否在ipython_config.py中设置了特定参数?

Is it possible to set the default path? Is there a particular parameter to set in ipython_config.py?

推荐答案

一种方法是使用启动.py 文件。它应该位于以下地方:

One way is to use your startup.py file. It should be located somewhere like:

C:/Users/yourname/.ipython/profile_default

如果它已经存在,请创建它。然后使用

If it's not there already, create it. Then use

import os
os.chdir('C:/Users/mypath')

这两行将在IPython启动时运行。

Those two lines will then be run at IPython startup.

来源:IPython.org> 启动文件

Source: IPython.org > Startup Files

这篇关于如何在IPython中自动设置默认路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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