1
$\begingroup$

I have compiled Blender 2.79b as a Python3 module on Ubuntu 16.04 LTS. I install an addon using bpy.ops.wm.addon_install(), enable it using bpy.ops.wm.addon_enable(module='packageName) and save the user preferences using bpy.ops.wm.save_userpref(). However, after I open Python3 again and do import bpy I cannot see the addon API's being added to the bpy module. If I run the same exact "addon installation" script when using Blender with the GUI everything works fine, but not when I have compiled Blender as a Python module. So I wonder, does anyone know whether I'm doing something wrong and how I can fix this?

In case you're wondering, I am trying to install Armory addon and below is the script I used to do the installation:

installArmory.sh

wget -O armsdk.zip https://www.dropbox.com/s/a17prr2hzsjkfog/armsdk.zip?dl=1
python3 installArmory.py

installArmory.py

import bpy, os, zipfile

with zipfile.ZipFile("armsdk.zip","r") as zip_ref:
    zip_ref.extractall(os.getcwd() + '/')

# Install the addon
bpy.ops.wm.addon_install(filepath=os.getcwd() + '/armsdk/armory/blender/addon/armory.py')
bpy.ops.wm.addon_enable(module='armory')

# Set the SDK path
user_prefs = bpy.context.user_preferences
addon_prefs = user_prefs.addons['armory'].preferences
addon_prefs.sdk_path = os.getcwd() + '/armsdk'

bpy.ops.wm.save_userpref()
$\endgroup$
2
  • $\begingroup$ I don't believe loading the bpy module will read the startup file that has the enabled addons saved. Look at the length of user_prefs.addons before and after calling bpy.ops.wm.read_homefile(). That would mean opening a blend after read_homefile or enable addons each time you start python and import bpy. $\endgroup$
    – sambler
    Commented Sep 18, 2018 at 5:09
  • $\begingroup$ @sambler I think I found a [temporary] solution to this problem. See my answer $\endgroup$
    – Amir
    Commented Sep 18, 2018 at 15:42

1 Answer 1

0
$\begingroup$

I think I could find a way around this but I don't think this will work for all addons that require restarting Blender, but it works for Armory.

Here are the steps:

# Install the addon
bpy.ops.wm.addon_install(filepath=os.getcwd() + '/armsdk/armory/blender/addon/armory.py')
bpy.ops.wm.addon_enable(module='armory')

# Set the SDK path (Armory-specific)
user_prefs = bpy.context.user_preferences
addon_prefs = user_prefs.addons['armory'].preferences
addon_prefs.sdk_path = os.getcwd() + '/armsdk'

# Use the `start()` function of `bpy.ops.arm_addon` to enable it.
bpy.ops.arm_addon.start()

Now arm shows up in bpy.ops. I don't think all addons have a function like start() that Armory has.

$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .