IPython 工作流(编辑、运行)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3438531/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
IPython workflow (edit, run)
提问by compie
Is there a GUI for IPython that allows me to open/run/edit Python files? My way of working in IDLE is to have two windows open: the shell and a .py file. I edit the .py file, run it, and interact with the results in the shell.
是否有用于 IPython 的 GUI 允许我打开/运行/编辑 Python 文件?我在 IDLE 中的工作方式是打开两个窗口:shell 和一个 .py 文件。我编辑 .py 文件,运行它,并与 shell 中的结果进行交互。
Is it possible to use IPython like this? Or is there an alternative way of working?
是否可以像这样使用 IPython?或者有其他的工作方式吗?
采纳答案by Wayne Werner
When I'm working with python, I usually have two terminal windows open - one with IPython, and the other with a fairly customized Vim.
当我使用 python 时,我通常会打开两个终端窗口——一个使用 IPython,另一个使用相当定制的 Vim。
Two good resources:
两个好资源:
- http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
- http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/
- http://blog.dispatched.ch/2009/05/24/vim-as-python-ide/
- http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/
Though it sounds like what you want is IPython's magic function %ed/%edit:
虽然听起来你想要的是 IPython 的魔法函数%ed/ %edit:
An example of what you can do:
您可以执行的操作的示例:
In [72]: %ed
IPython will make a temporary file named: c:\docume~1\wjwe312\locals~1\temp\ipython_edit_ar8veu.py
In the file I put:
在我放的文件中:
x = "Hello World"
print 3
After saving and quitting the file:
保存并退出文件后:
Editing... done. Executing edited code...
3
Out[72]: "x = 'Hello world'\nprint 3\n"
In [73]: x
Out[73]: 'Hello world'
You can define functions or anything else - just remember that the contents of the file will be executed when you close it.
你可以定义函数或其他任何东西——请记住,当你关闭文件时,文件的内容将被执行。
Another similar workflow is to cdto the directory containing your Python script that you're editing with your favorite editor. Then you can %runthe script from within IPython and you'll have access to everything defined in the file. For instance, if you have the following in the file test.pyin your /home/myselfdirectory:
另一个类似的工作流程是到cd包含您正在使用您喜欢的编辑器编辑的 Python 脚本的目录。然后,您可以%run从 IPython 中编写脚本,并且可以访问文件中定义的所有内容。例如,如果您test.py的/home/myself目录中的文件中有以下内容:
class Tester(object):
def __init__(self):
print "hi"
def knightme(name):
print "Hello, Sir ", name
Then you can do the following:
然后您可以执行以下操作:
In [42]: cd /home/myself
/home/myself
In [43]: %run test.py # <Tab> autocomplete also works
In [44]: knightme('John')
Hello, Sir John
In [45]: t = Tester()
Hi
Either a mix or one of those workflows should give you something very similar to the way you're used to working in IDLE.
这些工作流程的混合或其中之一应该会为您提供与您习惯于在 IDLE 中工作的方式非常相似的东西。
回答by Joe Kington
Personally, I use what @Wayne suggested, a combination of vim and ipython...
就我个人而言,我使用@Wayne 建议的,vim 和 ipython 的组合......
However, if you'd prefer a different approach, take a look at spyder.
但是,如果您更喜欢不同的方法,请查看spyder。
As of the latest version (1.1) ipython should be fully integrated. If you download an earlier version, things will work fine with ipython as an external shell, but you won't get a few of spyder's nifty features (like viewing all of the currently defined variables in the workspace window).
从最新版本 (1.1) 开始,应该完全集成 ipython。如果您下载早期版本,使用 ipython 作为外部 shell 会正常工作,但您将无法获得 spyder 的一些漂亮功能(例如在工作区窗口中查看所有当前定义的变量)。
Spyder is definitely a bit heavyweight, but it's an interesting project.
Spyder 确实有点重量级,但它是一个有趣的项目。
Another (very, very, new) similar project to take a look at is iep. It will (sort-of) work with ipython as shell, and I'd be willing to be bet that nicer ipython integration will be along before too long. At any rate, iep is essentially a more lightweight alternative to spyder.
另一个(非常,非常,新)类似的项目是iep。它将(某种程度上)与 ipython 作为 shell 一起工作,我愿意打赌,不久之后就会有更好的 ipython 集成。无论如何,iep 本质上是 spyder 的更轻量级的替代品。
Both of these are oriented towards scientific computing, and so have nice integration with things like matplotlib (and thus can automatically run gui main loops in a seperate thread). They're not quite like "normal" IDE's but they may fill the niche you're looking for quite nicely.
这两个都是面向科学计算的,因此与 matplotlib 之类的东西有很好的集成(因此可以在单独的线程中自动运行 gui 主循环)。它们不太像“普通”IDE,但它们可能会很好地填补您正在寻找的利基市场。
回答by Joe Kington
Spyder, previously known as SPyderlib / Spyder2
Spyder,以前称为 SPyderlib / Spyder2
Pretty lightweight, fast and support almost all featuresyou will ever need to work with a python project. It can edit and run .py files in an embedded IPython instance and then interact with them, set breakpoints, etc.
非常轻量级、快速并且支持几乎所有你在使用 python 项目时需要的功能。它可以在嵌入式 IPython 实例中编辑和运行 .py 文件,然后与它们交互、设置断点等。
回答by ying17zi
If you like the work-flow under Matlab, then you probably should try the following two:
如果您喜欢 下的工作流程Matlab,那么您可能应该尝试以下两个:
1, Try the combination of Spyderand Vim.
1,尝试的组合Spyder和Vim。
Edit python files in
Vim(Spydercan reload the file automatically)Run the code in
Spyder(in the same interpreter, which is important for me):Use
F9to run the current fileCtrl+F9to run the selected block
在
Vim(Spyder可以自动重新加载文件)中编辑python文件运行代码
Spyder(在同一个解释器中,这对我很重要):使用
F9运行当前文件Ctrl+F9运行选定的块
2, Use Vim+ conque-shell. (on google code)
2、使用Vim+conque-shell。(在谷歌代码上)
Open your preferred
Python interpreterinVim,e.g., just
:ConqueTermSplit python.then visual select some
Pythoncodepress
F9to paste and run it in thePython interpreter buffer.
打开您喜欢
Python interpreter的Vim,例如,只是
:ConqueTermSplit python。然后视觉选择一些
Python代码按
F9粘贴并在Python interpreter buffer.
Note: a few more:
注意:还有一些:
:ConqueTermVSplit python,:ConqueTerm python:ConqueTermVSplit rlwrap pythonIf your interpretor misses
readline, you can userlwrap.
:ConqueTermVSplit python,:ConqueTerm python:ConqueTermVSplit rlwrap python如果您的解释器未命中
readline,您可以使用rlwrap.
回答by Hypercube
Personally, I like PyScripter. Unfortunately, it only works on Windows, but also runs perfectly in Wine.
就个人而言,我喜欢PyScripter。不幸的是,它只适用于 Windows,但在 Wine 中也能完美运行。
回答by pyslices
You might like PySlices...
你可能喜欢PySlices...
It's kind of a shell/editor hybrid that lets you save your session as special (barely) modified python files called .pyslice files.
它是一种 shell/编辑器混合体,可让您将会话保存为称为 .pyslice 文件的特殊(几乎没有)修改过的 Python 文件。
It's now part of wxPython, so just install that (v2.8.11 or later) and run "python -m wx.py.PySlices" on the command line to launch it.
它现在是wxPython的一部分,所以只需安装它(v2.8.11 或更高版本)并在命令行上运行“python -m wx.py.PySlices”来启动它。
That said, I still end up using an external editor for scripts (geany).
也就是说,我最终仍然使用外部编辑器来编写脚本(geany)。
回答by Ravi
sudo apt-get install ipython
Once you are done with installing ipython.
完成安装 ipython 后。
Start ipython from terminal (just hit ipythonin the ternminal)
从终端启动 ipython(只需ipython在终端中点击)
To run ravi.pyfile all you need to do is
要运行ravi.py文件,您需要做的就是
%run ravi.py
回答by Roger
The latest version of IdleXsupports IPython within IDLE, as well as the %edit magic. You can run your files from the IDLE editor within the IPython shell many ways, either by F5 (run everything), F9 (run a selection), or Ctrl+Enter (run a subcode).
最新版本的IdleX支持 IDLE 中的 IPython,以及 %edit 魔法。您可以通过 F5(运行所有内容)、F9(运行选择)或 Ctrl+Enter(运行子代码)从 IPython shell 中的 IDLE 编辑器运行您的文件。
回答by lilSebastian
Try Spyder, I have spent all day trying to find an IDE which has the functionality of ipython and Spyder just kicks it out of the park..
试试 Spyder,我花了一整天的时间试图找到一个具有 ipython 功能的 IDE,而 Spyder 只是把它踢出了公园..
Autocomplete is top notch right from install, no config files and all that crap, and it has an Ipython terminal in the corner for you to instantly run your code.
自动完成从安装开始就是一流的,没有配置文件和所有废话,它在角落里有一个 Ipython 终端,你可以立即运行你的代码。
big thumbs up
竖起大拇指


