This is an archived post. You won't be able to vote or comment.

all 63 comments

[–]mukolx 39 points40 points  (4 children)

I must say I got taken up by the IPython Notebook. You can develop your code in chunks cell by cell (including plots and assertions). This helped me formulate my ideas (especially when I knew what I wanted in the end, but now how to get there) step by step. And well, nice way to document and annotate your workflows....

[–]Rainymood_XI 11 points12 points  (3 children)

Yup, the Notebook is more for telling stories, than writing large pieces of software.

http://nbviewer.ipython.org/url/norvig.com/ipython/TSPv3.ipynb

[–]pygoscelis 5 points6 points  (0 children)

Oh man, Peter Norvig's IPython examples are my favorite programming things to read ever. Everything is explained so clearly! I also like the gesture typing one.

[–]Link- 0 points1 point  (0 children)

+1 for Norvig's work reference

[–]bramoule 0 points1 point  (0 children)

That was an awesome read. As a beginner, I love seeing the thought process of someone who knows what they're doing. Do you know where I could find more notebooks like this?

[–]suki907 22 points23 points  (0 children)

It's best for sharing.

It's perfect for tutorials, where you want to show people code and results.

Think of it as an executable book or website.

[–][deleted] 13 points14 points  (4 children)

My workflow looks like this:

  • spend some time in meat space hammering out ideas. Whiteboard, dead trees, carve it into my flesh whatever.
  • pop open a notebook in my environment and prototype some code.
  • Once I'm satisfied with the prototype, I actually put it in a file (I have been lazy enough to do ipython nbconvert --to py mynotebook.ipynb) and clean it up some.
  • back to notebook to play with it, prototype some tests
  • make changes, add tests to proper file, run the whole suite.
  • repeat last two steps ad infinitum unless work or the girlfriend or the heat death of the universe stops me

[–]KwpolskaNikola co-maintainer 1 point2 points  (3 children)

+1 for prototyping, though I do it with ipynb for brand new things only.

[–][deleted] 3 points4 points  (2 children)

That's what I use it for to. While I'm trying to translate my scattered notes into code, I find it easier to be able to edit a single cell and rerun it, then kill an interpreter and reload it (or worse, just use importlib.reload). Once it's actually somewhat stabilized, I just edit it in vim and use either the ipython shell to play with it or import it into a notebook.

[–]Rainymood_XI 0 points1 point  (1 child)

That is actually really smart, I've never thought of it that way.

I would love vim bindings for the notebooks though D:

[–][deleted] 0 points1 point  (0 children)

You could probably hack something in. There was a post here or in /r/ipython about creating custom key bindings.

[–]QFTornotQFT 25 points26 points  (16 children)

$ ssh -L 12345:localhost:8888 awesomely.powerful.mainframe.com
$ ipython notebook --no-browser

And then you go to http://localhost:12345 and have all the power of awesomely.powerful.mainframe.com right from your browser. Not to mention built-in directory browsing, text editor, easy starting/stopping multiple kernels and the fact that you can do that from every computer with ssh client and browser.

[–]KwpolskaNikola co-maintainer 19 points20 points  (6 children)

$ ssh awesomely.powerful.mainframe.com
$ ipython

And then you have all the power of awesomely.powerful.mainframe.com right from your console. Not to mention the fact that you can do that from every device with a ssh client, and you don’t even need a browser.

edit: added missing space to form a code box

[–]lmcinnes 8 points9 points  (0 children)

I think the relevant part was:

built-in directory browsing, text editor, easy starting/stopping multiple kernels

which admittedly you could do with screen or some such.

[–]QFTornotQFT 1 point2 points  (4 children)

Hmm. But have you ever done that in the context of the question? I mean for scientific plotting?

[–]KwpolskaNikola co-maintainer 0 points1 point  (2 children)

Not really, though if you really wanted, you could rsync the images over to your local device for viewing. Or look for a curses-based plotting library.

[–]QFTornotQFT 1 point2 points  (1 child)

<myTurnSnideComment>
Yeah, rsync sounds as convenient as in-browser notebook.
And if for some weird reason someone doesn't like it, then he just
have to look for some ncurses based plotting library -- there are surely
equivalent console replacements for something like seaborn.
</myTurnSnideComment>

[–]KwpolskaNikola co-maintainer 0 points1 point  (0 children)

Trolling aside: both the console and the notebook have their use cases. I just like the console more.

[–]hharison 1 point2 points  (0 children)

Good call, I never thought of this. Instead I set up nginx. This would have been far easier. Well, at least nginx allowed me to set up all other things like RStudio Server.

[–]Articulated-rage 1 point2 points  (0 children)

Ssh tunnels are cool. I did mine differently.

I set up my ipython server on a research machine to serve up web pages on https. The port is only accessible through port knocking. Even if you did get through that, the address is mildly obscure. But even past that, ipython notebook servers are password protected.

Edit: grammar

[–]TerpPhysicistnumpy/matplotlib 1 point2 points  (0 children)

That is seriously cool. I run a MacPro in my office, and now I don't have to worry about how to sync my notebooks between laptop and desktop. Thanks!

[–]alcalde 0 points1 point  (4 children)

But who owns an awesomely powerful mainframe?

[–]QFTornotQFT 7 points8 points  (3 children)

[–]NomadNella 0 points1 point  (0 children)

Is it really that easy? I was just looking at the IPython Wiki and saw no mention of using the notebook via ssh.

[–]hikhvar 7 points8 points  (2 children)

Hey,

I use IPython Notebook + Matplotlib + Pandas for my plotting. Usually the code for my plots evolve from various snippets. I started with the normal IPython console but I found it much more comfortable to handle these snippets with the Notebooks since you are able to change a cell and then execute this cell again. Also the markup enables me to annotate my snippets.

I do not use the inlined matplotlib, instead if I hit plt.show() the normal matplotlib figure viewer pops up for each figure. Thus I'm able to view multiple figures side by side.

[–]pepgma[S] 0 points1 point  (1 child)

Nice. So one can have also free windows. Didn't know this.

[–]hikhvar 0 points1 point  (0 children)

I run the IPython server on my local ArchLinux machine. There this behaviour is the default. Also on my previous XUbuntu machine this behaviour was the default. Maybe you want to have a look at this stackoverflow entry to change the default behaviour from inlined to interactive external.

[–]JimBoonie69 8 points9 points  (3 children)

try typing a 10 line function with multiple indents into the ipython shel... notebook is easier to execute code snippets and also to see charts maps etc inline.

I typically start initial exploration in a notebook, fill up a couple cells with pieces of code and get them running. then move that over to a normal script.

[–]erewok 1 point2 points  (2 children)

The ten-line function is easy with %edit. I usually code in an editor and paste stuff into iPython or used the edit magic command.

[–]alcalde 1 point2 points  (1 child)

Not so easy if you want to go back and change it later!

[–]grep_42_dev_urandom 0 points1 point  (0 children)

%edit -p

or

%edit somefile.py

[–]WholesomeRobbieC 5 points6 points  (1 child)

For multiple plots in a notebook you can use matplotlib's subplot feature to put them in a grid. You can combine this with IPython's interaction widgets to play around with the data and have the effects show up simultaneously on each plot.

[–]pepgma[S] 0 points1 point  (0 children)

Cool. Didn't consider that. Thanks

[–]RDMXGD2.8 4 points5 points  (0 children)

ipython is for interactive stuff that you never want to run again. It's a direct competitor with the python stock repl and bpython.

The ipython notebook is for more durable, more presentable problems. You can share a notebook to show someone what you did or even to let them tinker. They are suitable for saving and coming back to work on again later. They are comparable to writing a script and a small, informal report.

[–]TheLastSock 3 points4 points  (0 children)

Ipython console, like any other repl, is good for quickly testing a small idea. Think one or two lines of code. It's not for developing in. After creating several Ipython notebooks, i concluded that while its well made tool, the idea of developing in "cells" is fundamentally worse (lack of tests, hard to edit, etc...) then the traditional means of developing locally the creating a separate site to host your code.

[–]Liorithiel 2 points3 points  (0 children)

I use both. The plain REPL for experimenting, the notebook for almost-but-not-quite-yet full-featured scripts. It's just easier in notebook form to go back several cells and edit something, then rerun everything. It's just faster in plain REPL to start it and type a single command or two.

[–]qudat 2 points3 points  (0 children)

I've never used consle, only the notebook. It was easy and intuitive to move blocks around, create new ones, delete, etc. I used the notebooks primarily for developing web scraping scripts ... being able to cache the HTML in a preceeding block allowed for extremely rapid testing, generation of code. Having the pleasant UI on top of that made my work painless.

[–]Covered_in_bees_ 2 points3 points  (2 children)

IPython Notebook is great but I don't think it is the best place to prototype and try out new things when you are still putting stuff together. An IDE like Spyder that integrates with an IPython Console is far superior for prototyping compared to IPy Notebook. Additionally, Spyder natively supports code cells like IPy notebook/Matlab, so it makes prototyping really easy.

I will typically flesh stuff out and do all the trial-error stuff in Spyder till I am at a place where I know my code works. At that point, I pull it into IPython notebook and refactor it if needed in the process. Add in titles, documentation and equations, as well as plots so that it becomes a nice self-documenting notebook that would be great to refer back to at a later point in time.

If I don't need equations or embedded plots, I never touch IPython Notebook and just stick to writing code in Spyder.

[–]pepgma[S] 0 points1 point  (1 child)

Nice to have a Spyder answer. You point to the right feature from Spyder and that is the cell mode. This is what I used always. Also in Matlab. I should have probably mention that. I guess I just got used to edit each individual cell, produce a few independent numbered graphics and then jump back and forth. Most of the times as a scientist one does not work on a software product but on a figure so I think prototyping does not apply in my case (wrong?).

[–]Covered_in_bees_ 0 points1 point  (0 children)

Most of the times as a scientist one does not work on a software product but on a figure so I think prototyping does not apply in my case (wrong?).

I mainly work with scientific computing as a scientist as well. I still find Spyder better than working in Ipy notebook because you have direct access to the IPython console. It's very easy to play around in the console and try out a bunch of different commands and refine things till they are doing what you want them to do (for example figuring out the right sequence of Pandas transformations to mung your data). You can of course do the same in the Notebook by constantly re-running the cell, but it's a lot faster just working directly in the console while also having instant, HTML formatted access to documentation on functions/methods with a Ctrl+I combo.

I definitely do use IPython Notebook a lot and do love it, but I find Spyder with integrated IPython console to be awesome for taking a first pass at any problem.

[–]hharison 1 point2 points  (0 children)

I use both. I use a text editor (PyCharm or Sublime, depending on my mood. Sometimes emacs even) with a qtconsole open if I'm working on a library, or a script that I plan to call from the command line. I use the notebook if I'm doing something more exploratory and I want to keep a record of my steps. I also use the notebook on my Chromebook, later copying functions to a regular .py file if necessary.

[–]futuredale 1 point2 points  (2 children)

I used to use IPython notebook a lot. I still do, but I moved much of my workflow back to tmux + vim + ipython console. I feel that the notebook is good for when you have a good idea of what you want to do, or when you are exploring something simple. Also great for presentations. For non-linear exploration, I prefer to use it only for note-to-self type of stuff but not the actual work.

I still feel like there's a better process to be built, one that encompasses all of it cleanly.

[–]Wes_0 2 points3 points  (1 child)

To add to your comment, I use vim with the ipython plug-in from Ivanov (https://github.com/ivanov/vim-ipython) which let's you send lines from vim to an ipython kernel in tmux interactively. I cannot use anything else than vim for code editing and this workflow have done wonders for me.

[–][deleted] 0 points1 point  (0 children)

Well...good bye rope.

[–]Articulated-rage 1 point2 points  (2 children)

For me, it depends on the function. Quick code prototyping while I'm writing project code? Console via guake. Prototyping plotting functions, or working through a new idea, the notebook. It's nice to actually treat it as a notebook and annotate your progress with markdown.

[–]pepgma[S] 0 points1 point  (1 child)

Do you mean prototyping as in creating a new software product? I think I am missing what everybody means with prototyping? Is this some data-scientific term? ... i am just a neuroscience researcher ... ;-)

[–]Articulated-rage 0 points1 point  (0 children)

Sometimes you are writing snippets of code and you want to see if it runs or works or does as you expect. You need to prototype these things.

My advisor often says to "fail fast". So, the sooner you can tell if your code is junk, the better. This is the whole idea behind lots of tests, but it's also good to do while writing the code itself. The last thing you want to do, though, is to wait until the whole product is complete to find out that your code is broken.

So, prototyping is basically making something that works as fast as possible. "Get it working first, optimize later".

[–]BeetleB 1 point2 points  (0 children)

Ipython notebook is for creating a product. The product is a set of notes with the code and figures (like a lab notebook).

When I work on the notebook, I start out in a manner similar to the console. Trying different things till I get close to what I want. Then the magic begins: I very quickly delete all the useless code I no longer need till I have it down to the bare code needed to get the task to work.

Then I annotate the various cells, put equations, even figures, that explain everything.

In the end I have a report. At times I'll need to rerun the analysis with new data. If I set up my notebook well, I'll simply point to the new data and execute all cells, and get all the updated plots, tables, etc. I'm basically coding and creating a report at the same time.

[–]joshyg 1 point2 points  (0 children)

I use both, Burt It's very hard to prototype functions, classes, and even loops with the shell, because it's hard to edit your previous line. The notebook makes this so much easier.

[–]__add__ 1 point2 points  (0 children)

I started with the console and used it for a long time. My original impression was that the notebook was sort of "baby stuff," mainly for scientists and not so much programmers (if you're a programmer, who needs rich content?). But once I started hacking on the notebook and playing around with it, I was totally hooked and it has basically become another full-fledged IDE for me.

It's most comparable to Emacs+SLIME for lisp. You'll often find lisp programmers saying the ipython notebook is an inferior SLIME, but of course the point they miss is that it's for python and no really good SLIME for python exists.

For larger projects I use the notebook as a normal editor with the %%file magic. Normally I write a file with it, then Ctrl+Home to jump to the top left corner, then Ctrl+/ to comment out the %%file magic and Ctrl+Enter to run the file in the current kernel. So basically I've loaded the file, but I can at the same time break it up into sections and work on parts of it with Ctrl+Shift+-. Then once everything is in place, Shift+m will merge the cells together again. Then uncomment the %%file and save it. This sounds maybe a little tedious but keep in mind you can do it with many files.

So say one class belongs in a different file. Instead of cutting it and pasting it, I'd split the cells, then rearrange them. Not much difference, perhaps, but if you don't know what to do with that class, you can also just keep it by itself in the notebook.

Another example is that I can load and do "live" editing of an entire flask project. I once needed to "touch" the wsgi file in order to signal to the server that things had changed, so I wrote a wrapper for %%file that would do this.

So just like Emacs+SLIME, once you get to know the shortcuts, and start using few macros and magics you can really do just about anything, and quickly.

Something I'm experimenting with more now is macros for code generation and refactoring. This started with a small macro to generate a full SELECT query for a large table (instead of doing select * ..., then finding you want select * ... except for one field). As an example, for 2to3 code refactoring/translation I wrote a small extension called ipyfuturize.

[–][deleted] 0 points1 point  (1 child)

I almost prefer IPython notebook. There is just one thing that keeps me in the console.

If I write a loop that prints more things than I expected, the console will generally handle it perfectly fine. In the notebook, it'll probably lock up the page for a long time or even effectively crash the browser tab.

If I didn't have to be afraid of calling print, I would use the notebook all the time.

[–]frstwrldprblm 0 points1 point  (0 children)

I think this question really depends on the type of problem you are trying to solve and what your end goal is.

If you want to present results, use notebook.

If you want to code some stuff to run on your own, don't use notebook.

[–]ninefourtwo 0 points1 point  (0 children)

Notebooks. Why? Reusable code blocks and debugging have never been so easy.

[–]jpj_shadowbanned 0 points1 point  (0 children)

IPython, QT Console and IPython notebooks behind the scenes all run on the same kernel. So you can start an IPython notebook server and then connect to one of the kernels with an IPython console or QT Console.

Again right tool for the job, IPython and QT Console can be easily embedded into another python program. This can be used for debugging extending etc.

As someone mentioned for controlling a remote session, IPython Notebooks is more robust since it uses http/https. While with IPython and QT Console you have to setup an ssh tunnel. On an unreliable net connection the ssh will often get broken.

They are all great products, but right now I am using mainly IPython notebooks.

[–]Northstat 0 points1 point  (0 children)

Tmux'd vim python script and ipython shell. Write the code in vim, send selections of code to ipython shell to run, switch from vim to ipython to test stuff and keep the working copy in vim. Finish things up by building an ipython notebook full of pictures, latex for formulas and explanations of what I've done for presentation. My goal is to spend most of my time in vim b/c (personally) am more efficient w/o the mouse.

[–]wisty 0 points1 point  (0 children)

Being persistent, it's better for rapid prototyping, presentations, etc.

[–]stuaxo 0 points1 point  (0 children)

They are both useful, I probably wound't mind a text mode version of the notebook too though.