Blender has a Python scripting API, but it is limited to an interpreter launched within Blender. This Jupyter kernel starts a Blender instance with an async kernel running inside of it. This means that you can script from hydrogen or a Notebook while still using the Blender UI.
Cheng-chi made a comprehensive installer at https://github.com/cheng-chi/blender_notebook hosted on pip! Instructions are there
Find your DATA_DIR with jupyter --data-dir. Your KERNEL_DIR is DATA_DIR/kernels/
git clone https://github.com/cameronfr/BlenderKernel- In
kernel.json, replaceKERNEL_DIRwith yourKERNEL_DIR - In
KernelFile.py, replacepythonPathwith a python site-packages path (e.g. runpython -c 'import site; print(site.getsitepackages())'to find it) - In
KernelFile.py, replaceblenderPathwith a path to your Blender executable (e.g./Applications/Blender.app/Contents/MacOS/Blenderon Mac) mv BlenderKernel KERNEL_DIR/blender
Use jupyter kernelspec list to make sure the kernel is listed, then launch the kernel as you would any other.
To test on the default cube scene,
- run
import bpy - the Cube should move when you run
bpy.data.objects["Cube"].location[0] += 0.5.
- the kernel should persist when opening other .blend files
- however, if you encounter an error like
ReferenceError: StructRNA of type Object has been removed, the solution is todel objwhereobjis something you assigned to a Blender object in a previously opened file.