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
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
Ran into the same issue and received a couple helpful responses on devtalk. My solution is based on the top solution in this post, but the second one ran properly as well.
import subprocess
import sys
from pathlib import Path
# OS independent (Windows: bin\python.exe; Mac/Linux: bin/python3.7m)
py_path = Path(sys.prefix) / "bin"
# first file that starts with "python" in "bin" dir
py_exec = next(py_path.glob("python*"))
# ensure pip is installed & update
subprocess.call([str(py_exec), "-m", "ensurepip"])
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"])
Assuming the above block is incorporated into the init file of an add-on, users shouldn't need to manually install the dependencies.
Warnings:
- On Windows, Blender must be run in Administrator mode. In one case, I had to restart Blender before using the installed dependency.
- Installing dependencies like this requires an active internet connection
One possible solution is to keep add-on and dependencies installation separate, i.e:
First install deps into Blender's python:
path/to/blender/python -m ensurepip
and path/to/blender/python -m pip install -U pip
pip install <whatever need be>
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.