Hi, the last few months I’ve been using blender quite a bit for scientific visualizations and I’ve ended up implementing a python library for basic plotting to make the process easier: GitHub - Linusnie/blender-plots: Python API for plotting in blender. Since the script editor in the GUI is quite limited I’ve been using blender notebook so that I can run analysis and plots from the same python environment in an interactive way
However one issue with this approach is that I’ll typically have a different python dependencies for each project I’m working on. So I end up having to install my (possibly conflicting) dependencies to the python interpreter in the blender install folder every time I switch projects, which gets messy quickly
Ideally I’d like to be able to do one of the following:
tell blender what python interpreter to use with when I start it. This way I would just need to ensure bpy is installed in every new environment I create
be able to launch blender from inside any python process and access the API. Something like e.g. import blender; bpy = blender.new("/path/to/executable") would launch a non-blocking blender GUI and then allow you to use the python API via bpy
Any thoughts? Is there a way to accomplish either of those options?
after trying some different options I’ve found creating a separate blender ipython kernel for each project works pretty well. For each new python environment:
Activate the environment with source path/to/new_venv/bin/activate
run python -m pip install blender_notebook
run blender_notebook install --blender-exec=... --kernel-name=blender_new_venv
This way the site-packages paths from new_venv will automatically be added to sys.path at kernel startup (see here).
One caveat is that any library already installed in the blender python interpreter (e.g. numpy) will override whatever the corresponding version in new_venv is. This could possibly be reversed by changing the line linked earlier to sys.path.insert(1, RUNTIME_CONFIG['python_path']) which would give the venv packages higher priority (though risks breaking the API)