Skip to content

Using addons inside containers

Or Fleisher edited this page Mar 4, 2021 · 1 revision

Setting up the addon

To get started with using addons inside containers you will need

  • Docker (See getting started)
  • A folder with the addon .zip file and a Python file called bpy_activate_addon.py

Running the container

When running the container, you will need to mount the folder where the addon zip file and the Python script live as a Docker volume. cd into the folder where the addon and Python script live and run

docker run --gpus all \
           -w /addon-test \
           --rm -it \
           -v $(pwd):/addon-test \
           -t nytimes/blender:latest \
           /bin/bash

This should launch bash in the container. If you run the ls command, you should be able to see the addon .zip file and Python script.

Installing and enabling the addon from Python

Open the bpy_activate_addon.py in a code editor and use the following snippet to install and enable your addon (make sure you change the name of the addon to the actual name)

import bpy

# Register the addon and enable it
bpy.ops.preferences.addon_install(filepath='./your-addon-file.zip')
bpy.ops.preferences.addon_enable(module='your-addon')

# Use the addon directly from Python
# ...

Now run Blender headless inside the container with the Python file, it would look something like

blender --background --python ./bpy_activate_addon.py

Here is an example log of running the above with the Stop-motion-OBJ addon.

Blender Docker log from running addon script

If everything worked and you see a similar print you are ready to use the addon inside the container.