Can 3rd party modules (ex. SciPy) be installed when an add-on is installed?

Trying to use SciPy in an add-on such that it is automatically installed when users install the add-on.

Related discussions took place a few years ago (here’s one). But as this user notes, a lot of solutions would require end users to install a module before installing an add-on.

Why not have in the init method of your addon check for scipy, if not there run a python.exe subprocess to an external script to install it via pip?

2 Likes

We do that for the Rhinoceros 3D importer import_3dm - bootstrap pip using ensurepip, then install into a user script path that is in Blender sys.path using subprocess to all the Python executable that is bundled with Blender.

1 Like

Thanks @bsavery & @jesterKing. Provided a solution to the linked question. Happy to incorporate additional feedback should you think of anything.

Does this assume that the computer has an aactive internet connection? Or are you talking about installing it from some kind of zip bundle?

That is one downside. Another is that complex things like scipy often have other dependencies, dependencies which sometimes need to be compiled.

1 Like

just a heads up when blender is installed into program files on windows, that code will have run as administrator since regular users do not have write permissions there.

2 Likes

@kurk I see that @stiv and @LazyDodo already pointed out the obvious issues.

For the ensurepip part I suggest using the --user argument. And maybe it is even possible to specify a separate location outside of --user, but still writable for the regular user (think bpy.utils.script_path_user).

Then for actually using the bootstrapped pip to install modules definitely use bpy.utils.script_path_user() as a location. I believe that one of the sys.path entries is bpy.utils.script_path_user()+/addons/modules. This I use to install the rhino3dm dependency for my add-on import_3dm.

2 Likes