Instructions are from
https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule
Tested with Blender 2.93 on macOS 10.15.7
- Install xcode command line
sudo xcode-select -s /Applications/Xcode.app/Contents/Developer
-
Install python 3.7
https://www.python.org/ftp/python/3.7.9/python-3.7.9-macosx10.9.pkg -
Download blender build
mkdir ~/blender-git
cd ~/blender-git
git clone https://git.blender.org/blender.git
cd blender
make update
- Build blender python api Using the following solution
https://devtalk.blender.org/t/undefined-symbols-when-building-blender-as-python-module/7304/9 Change "WITH_OPENM" to OFF in CMakeLists.txt
make
cd ../build_darwin
make install
- build bpy
cd ~/blender-git/blender
make
cd ../build_darwin_bpy
make install
- Post make
cp ./bin/bpy.so /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/
mkdir -p /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/Resources
cp -R ./bin/2.93 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/Resources/
- Test
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7m -c "import bpy; bpy.ops.render.render(write_still=True)"
Blender executable
~/blender-git/build_darwin/bin/Blender.app/Contents/MacOS/Blender
# Test
~/blender-git/build_darwin/bin/Blender.app/Contents/MacOS/Blender --background --python test.py
# Install packages
~/blender-git/build_darwin/bin/Blender.app/Contents/Resources/2.93/python/bin/python3.7m -m pip install joblib
Blender python
~/blender-git/build_darwin/bin/Blender.app/Contents/Resources/2.93/python/bin/python3.7m
/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7