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)