Adding dependencies to blender extension

Blender 4.2.0 added extensions, which can be bundled with external 3rd-party libraries in the form of wheels. The downside to this, is that you have to download all the wheels for all the platforms for all the packages you want to, as well as their dependencies. It’s a lot to keep track of, and a large hassle to keep your dependencies updated, especially if the dependencies add or remove dependencies.

I wanted to make this all a lot easier for myself when creating a blender extension using a library I created which relies on many other dependencies. Which is why I created this program, Blender Extension Builder.

This program can be installed with just

pip install blender-extension-builder

When listing out all your dependencies in the blender_manifest.toml file, you just have to do

dependencies = [
  'pillow',
  'numpy',
]

You can then just run

bbext

And then it will then download all the wheels for these dependencies, and create a build folder, which will contain the code for the extension, as well as all the wheels, and a new blender_manifest.toml file, which lists out all the wheels.

Running the command like this will just download the wheels for your platform, however for distribution, you may want to download for all platforms. Which is why I also added these arguments.

bbext --all-wheels --split-platforms

This will download all the wheels for all the platforms, and --split-platforms does what the blender build command does (though this program will also create a universal build). The great thing about this, it will also check all the platforms the dpendencies are available for, and only include those, so you don’t end up claiming the extension is compatible with a platform, yet that platform doesn’t contain all the wheels.

There are a lot more stuff that this program is useful for.

  • Allowing the source code to be in a separate folder (such as src) while keeping the blender_manifest.toml file in the root.
  • If you don’t specify paths, only the source code folder will be in the extension. If you do specify paths, it will also copy whatever files you put in it (relative to the blender_manifest.toml file).
  • Automatic installation via the --install flag.
  • And more (I could also potentially add more features to make building extensions easier).

You can view more about this program on its github page.

Here’s an extension that I’ve been working on that uses this if you want to see a working example.

3 Likes