Advertisement

You're blocking ads, which pay for BlenderNation. Read about other ways to support us.

Using IPython with Blender

5

IPython is a Python console that's great to use, but that did not have compatibility with Blender yet. Mathias Panzenböck (panzi) changed that.

IPython is a Python console with several frontends (terminal, Qt, web). It reminds a bit of Mathematica & Co. because of the code cells. It is especially useful in a scientific context. Here is a read-only example of an IPython notebook. Here are some more examples.If it's not read-only you can add/edit/remove/execute code cells and write your Python script in that nice web based editor. It supports code completion and inline help. The nice thing is you can have nice Markdown text and the (image) output of the scripts directly in the same document as the code. (I didn't work out how to show Blender render output in a notebook, but I guess it should be relatively easy. Just load the written images.)

In non-scientific contexts it is still a nice Python shell. You can think of it as a better idle (the GUI Python shell included with Python). In the context of Blender one would use it to draft scripts, like you use the Python console that is integrated in Blender.

But if you want to use IPython to write and run a Blender script you have a problem. The bpy module is only accessible to embedded Blender scripts, it's not a stand alone module. But because IPython uses a separate process for the kernel (which executes the Python scripts) I could hook it all up so that the kernel to which the IPython frontend connects runs as Blender script, even though the frontend runs outside of Blender in the system's Python 3 installation.

B9TjZ0r

I wrote a little script that lets you run an IPython console or notebook in the context of Blender's embedded Python interpreter. This can be used to draft Blender scripts or for whatever you would use the integrated Python shell. See:

I wrote this because this article claims Blender has bad Python bindings.

When asked what's so bad about Blender's Python bindings in the reddit comments I was told that the .blend format is too complex (no idea what that has to do with anything) and you can't use IPython with blender. Well, now you can. See (I'm bloody-albatross there).

Maybe this script is of any use to other Blender scripters?

About the Author

Avatar image for Bart Veldhuizen
Bart Veldhuizen

I have a LONG history with Blender - I wrote some of the earliest Blender tutorials, worked for Not a Number and helped run the crowdfunding campaign that open sourced Blender (the first one on the internet!). I founded BlenderNation in 2006 and have been editing it every single day since then ;-) I also run the Blender Artists forum and I'm Head of Community at Sketchfab.

5 Comments

  1. Sounds as a small update, but its a major breakthrough i believe.
    Lets put it in perspective, now suddenly people with experience in ipython who untill would use
    matplotlib or other more simple drawing methods,
    have now suddenly the option to represent their scientific work, using blender.
    And with that there are chances for code xenogamy, maybe they will use /extend addons etc.

    • Yes, calling IPython.embed() let's you debug a script by spawning a console at that point. This script though lets you do the opposite: run a blender instance "in" IPython. It also gives you access to the GUI tools of the Qt console or IPython Notebooks. I don't know if this is actually any useful, but the critique was that you can't do that with blender. With my script you can.

  2. Nice hack. Doesn't change the fact that blender could do more to be easily integrateable into Python applications.

Leave A Reply

To add a profile picture to your message, register your email address with Gravatar.com. To protect your email address, create an account on BlenderNation and log in when posting a message.

Advertisement

×