如何在IPython中自动设置默认路径 [英] How to set default path automatically in IPython
问题描述
我使用WingIDE进行开发,使用Ipython运行脚本。我在几点上面临一些不便:
I'm using WingIDE for development and Ipython for running my scripts. I'm facing some inconvenience on several points:
-
每当我更新我的代码时,我都必须重新加载我的模块才能在IPython中更新它。为了解决这个问题,我在以下链接中点击了 Jomonsugi 的答案:如何在IPython中自动重新加载模块?
并且可以正常工作。
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屋!