Using IPython with Blender

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?

Advertisement