What does ipython have that bpython lacks and vice versa? How do the two differ?
If you just want an interactive interpreter, bpython should be fine. Just use it until you miss some feature you liked about IPython.
There are lots of features that IPython offers over bpython:
Special threading options. I like -gthread for experimenting with PyGTK and -pylab for matplotlib.
direct invocation of shell commands. cd in IPython is quite useful.
Full readline library support -- I can use the keyboard shortcuts I am used to.
Module reload facility - You can do a deep reload of a module after you have changed your code. This is very useful for testing and debugging.
Run functions in the background in a separate task with %bg.
A whole parallel programming environment (not really a feature you expect from an interactive Python shell, but IPython offers it).
This list could be nearly arbitrarily continued. And of course there will be lots of features in bpython lacking from IPython, but you did not ask for those.
So just use the one that works for you!
IPython Notebook (since 0.12) is a killer feature.
Related
I am mainly using IPython and I feel more comfortable in using a classic IPython REPL than the VSCode builtin Python Interactive window, therefore I would like to disable it, but I have no idea how.
I checked the VSCode documentation but I couldn't find any instructions on how to disable it.
At the moment I am using the ipython extension and I am very happy with that.
As stated in the document, it is precisely because of the use of "#%%".
So it wakes up the Jupyter code cells in vcscode.
Python has its default debugger called pdb, but there are a few alternatives created by the community. Two of them are ipdb and pdb++. They seem to cater to the same audience, they can both be run directly at the CLI and provide some niceties such as colored output and tab-completion.
Do they serve different purposes or are they simply competing debuggers with similar features?
I'm having trouble understanding when one would wish to use one over the other. There seem to even be people using both at the same time
I'm not a pdbpp expert, but to me ipdb comes with more features (IPython has many "magic" functions such as %timeit, %debug, etc that are handy), while pdbpp has a sticky mode that displays the source in the terminal as you step through (like GDB's TUI mode) and is more capable than the default pdb.
So they are both good options to debug, but my personal preference goes to ipdb because I'm used to work interactively from IPython. I've found I could set my main debugger to ipdb like so:
export PYTHONBREAKPOINT=ipdb.set_trace # or ipdb.sset_trace
And put breakpoint() in the Python source to debug. If pdbpp is also installed, I can invoke sticky from the ipdb session, which is neat.
I would really like to run my Win7 ipython interactively inside a proper terminal and shell provided by cygwin (mintty or rxvt would be great).
I have had some success with python, but IPython is not really cooperating. If we run this from rxvt bash prompt:
$ /cygdrive/c/pydir/python.exe -i
I end up with a fairly successful python interactive session. But vanilla python is just not as wonderful as IPython. So then I try this:
$ /cygdrive/c/pydir/ipython.exe
and the program just blocks the bash prompt, and seems to spawn an entirely separate process (which does not produce any windows, or show signs of stdin/stdout).
If instead I use this:
$ /cygdrive/c/pydir/python.exe -i /cygdrive/c/pydir/ipython-script.py
it is exciting at first, but you quickly realize that ipython is not properly engaging with the terminal. There is no readline support, poor cursor control, stdin seems to handle typical python, but there are no [out] prompts (although "prints" do spit out text), simple things like backspace/enter/tab seem completely broken (the cursor is very defiant), there is nothing like an ncurse buffer being maintained (you can just type over the ipy command prompts).
Once I have given up on the session, exiting becomes another problem. I can return to the bash prompt, but I have no standard input. It turns out that there is always a python.exe process hanging that must be killed from the Windows side (and it doesnt release stdin until it dies).
Is there a quick fix or alternate method to run Ipython in this manner? I can do most of my development using the cygwin binaries, but being able to run win32 binaries interactive would help tremendously when debugging/testing win32 specific python libraries.
P.S.:::: I really need tab-completion and clean output. I am trying to piece my way through a bunch of COM interfaces, and the only way I can get anywhere is with an interactive ipy session.
P.S.:::: I am using a 64-bit Cygwin and a 32-bit win32 python. Could this be simple mismatch?
Running win32 IPython.exe executables in cygwin is problematic at best. Best to run the cygwin Ipython version. Depending on the libraries you need, this can work just fine. But if you need to work with win32 compiled libraries, the cygwin Ipython will not work (as far as I know).
Overall, I still struggle for pleasant terminal experiences with ipython in Windows. There is no one solution that "just works". I have 3 different ways of interacting with IPython, depending on the job I need to get done.
Use cmd.exe (or Console.exe) and run the win32 ipython. This is the best way (in my opinion) for a vim+ipython workflow. This is very functional and fast. It will hurt your eyes a little, and still lacks a good "terminal" experience... but it will get the job done if you need to grind through some work. Extra Bonus: Seems like a few extra ipy %magics work better in this workflow.
Use cygwin and the ipython package that comes with cygwin. You lose "native" win32 support, but if you generally only need the standard library, this will look better and feel better (assuming you go all the way with CygwinX and run your favorite terminal).
Use win32 Ipython, and get QTConsole working. If your in Windows and you haven't already tried QTConsole, go get it right now and spend a little time setting it up. It can be extremely fast and pleasant (fonts that don't hurt my eyes!), and its loaded with features. Its biggest drawbacks: it doesn't handle some %magics well (like %edit, so I lose my vim+ipython workflow),it doesn't do system background processes well, and it won't always handle stdin/stdout like you would think. But, if you combine QTConsole with the cmd.exe ipython, and give it a little practice+patience, you can get a pretty decent "console" development workflow.
I could not understand the ipython library. This url provide the common feature but I could not core-relate it. http://ipython.org/ipython-doc/stable/interactive/tutorial.html
How to I use IPython to improve my day to day python application experience?
ipython is an improved interactive prompt, not a library. It has features like tab completion and profiles which are not present in the vanilla interactive prompt (which is running python without an input file). All features are listed on the page you cited.
So, it doesn't really improve your day to day python application experience (whatever that means), but it does provide benefits during development.
Also, there is an alternative, called bpython, it has quite great features, too.
do you do any scientific computing? ipython 0.12 has new functionality called ipython notebook that's really useful for data analysis. you can easily print graphs and data inline in your browser and reload your code. You can then print it as a pdf and make a nice report.
it's also useful for learning python due to ipython's functionality. you can quickly test and understand how certain functions operate. A few particularly useful functionality aside from tab completion
object?? gives you more information about the object
%history gives you a list of all your previous commands
%debug if you hit an error, this will put you into the debugger so you can quickly debug
besides from using a completely integrated IDE with debugger for python (like with Eclipse), is there any little tool for achieving this:
when running a program, i want to be able to hook somewhere into it (similar to inserting a print statement) and call a window with an object inspector (a tree view)
after closing the window, the program should resume
It doesnt need to be polished, not even absolutely stable, it could be introspection example code for some widget library like wx. Platform independent would be nice though (not a PyObjC program, or something like that on Windows).
Any Ideas ?
Edit:
Yes, i know about pdb, but I'm looking for a graphical tree of all the current objects.
Nevertheless, here is a nice introduction on how to use pdb (in this case in Django):
pdb + Django
Winpdb is a platform independent graphical GPL Python debugger with an object inspector.
It supports remote debugging over a network, multiple threads, namespace modification, embedded debugging, encrypted communication and is up to 20 times faster than pdb.
Some other features:
GPL license. Winpdb is Free Software.
Compatible with CPython 2.3 through 2.6 and Python 3000
Compatible with wxPython 2.6 through 2.8
Platform independent, and tested on Ubuntu Jaunty and Windows XP.
User Interfaces: rpdb2 is console based, while winpdb requires wxPython 2.6 or later.
Here's a screenshot that shows the local object tree at the top-left.
(source: winpdb.org)
pdb isn't windowed, it runs in a console, but it's the standard way to debug in Python programs.
Insert this where you want to stop:
import pdb;pdb.set_trace()
you'll get a prompt on stdout.
If a commercial solution is acceptable, Wingware may be the answer to the OP's desires (Wingware does have free versions, but I don't think they have the full debugging power he requires, which the for-pay versions do provide).
Python Debugging Techniques is worth reading. and it's Reddit's comment is worth reading too. I have really find some nice debug tricks from Brian's comment. such as this comment and this comment.
Of course, WingIDE is cool (for general Python coding and Python code debugging) and I use it everyday. unlucky for WingIDE still can't embedded a IPython at now.
You can use ipython, with the %debug statement. Once your code crashes, you can add breakpoints, see objects etc. A very crude way to kickoff the debugger is to raise Exception at some line of your code, run it in ipython, the type %debug when it crashes.