10
$\begingroup$

How to write my add-on so that when installed it also installs dependencies (let's say: scipy or numpy-quaternion)?

Does blender understand setuptools (setup.py)?

Thanks,

Note: I'm using blender 2.8

$\endgroup$
16
$\begingroup$

Ran into the same issue and received helpful responses on devtalk. There's also another post that was helpful when installing pip for 2.81.

2.81

import subprocess
import bpy

py_exec = bpy.app.binary_path_python
# ensure pip is installed & update
subprocess.call([str(py_exec), "-m", "ensurepip", "--user"])
subprocess.call([str(py_exec), "-m", "pip", "install", "--upgrade", "pip"])
# install dependencies using pip
# dependencies such as 'numpy' could be added to the end of this command's list
subprocess.call([str(py_exec),"-m", "pip", "install", "--user", "scipy"])

Warnings:

  • On Windows, Blender must be run in Administrator mode. Blender may need to restart before using the installed dependency.
  • Installing dependencies requires an active internet connection
| improve this answer | |
$\endgroup$
  • 1
    $\begingroup$ It is worth mentioning, for those pip installing dependencies that need to build, that the python sources need to be present in: PATH_TO_BLENDER/2.80/python/include/python3.7m/. Sources must match blender's python version and can be grabbed from: python.org/downloads/source. Otherwise an exception is thrown during installation mentioning the missing Python.h $\endgroup$ – gmagno Sep 24 '19 at 0:26
  • 1
    $\begingroup$ I don't know about older version, but to reach python executable in blender 2.83 you can use bpy.app.binary_path_python $\endgroup$ – Pullup Jun 26 at 15:24
3
$\begingroup$

One possible solution is to keep add-on and dependencies installation separate, i.e:

First install deps into Blender's python:

  1. ensure Blender's python installation has pip: path/to/blender/python -m ensurepip and path/to/blender/python -m pip install -U pip
  2. And pip install your dependencies: pip install <whatever need be>
  3. If any of the deps needs to be built, as opposed to installed from wheels, you have to ensure that the python includes are present, otherwise you will get an error about missing Python.h.

And then install the add-on.

This is not an elegant solution though, having to tell your users to go through this process is not convenient.

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.