MacOS - Blender as a Python Module: Build Errors

Hello forum,

I am attempting to get bpy.so building on MacOS Catalina. I recently purchased a Mac Mini and have refurbished it in order to get it in working order and have yet to successfully build Blender as a Python module due to multiple issues.

When following build steps at building Blender MacOS and building Blender as a Python module the build process fails at multiple points:

  1. install_deps.sh:
    a. Documentation should be updated to include brew install wget if install_deps.sh is meant to be run on MacOS
    b. Command not found: nproc similar to this
    c. **ERROR!** wget could not find http://sourceforge.net/projects/boost/files/boost/1.68.0/boost_.tar.bz2/download
  2. make bpy does not in fact build bpy.so but rather Blender.so, confusingly…
  3. make bpy fails at linking stage with multiple issues surrounding what seems to be the Ceres library see here
  4. Even cloning at a release tag does not seem to work. Consider the below, which doesn’t work:
mkdir blenderpy
cd blenderpy
git clone --branch v2.79 http://git.blender.org/blender.git
svn export https://svn.blender.org/svnroot/bf-blender/tags/blender-2.79-release/lib/
cd blender
build_files/build_environment/install_deps.sh
make update
make bpy

Is anyone able to get this module building on MacOS at the moment? What are the build steps? Following the basic build steps provided on the Wiki do not work for me on a fresh install of MacOS Catalina.

Thanks in advance.

Hi, thanks for letting us know.
Fixed in 2.81 and master branches:
developer.blender.org/rB3ceff8b7bc71ac1c89897ccb4a58d2917f38500d

2 Likes

Thanks for the quick reply.

I’m not sure what I’m doing wrong, but I cannot seem to get the Python module to build even on the master branch.

The build process I followed is here

However, at least bpy.so is attempting to build, rather than Blender.so, and that’s a step in the right direction.

Hey Tyler,

I’m trying to do the same and I’m seeing similar build fails – I’ve tried on macOS as well as Windows. I’ve posted about it on multiple forums without much help: here and here.

If all you need is a functioning bpy module, you should consider installing it via an anaconda environment (see the first link above). But if you are able to figure out how to build bpy.so, please let me know! I’ve love to see updated instructions on the build. I’ll keep trying as well and let you know if I have any success.

-Jack

@jacksund What errors exactly are you getting with bpy on Anaconda? Something to do with addons?

This may help; I have some experience with Blender as a Python module and addon installation.

In the meantime, I just tried following the build instructions closely using the blender-v2.81-release branch. Not sure why I’m getting a numpy error. install_deps.sh seems to imply that it’s installed correctly.

With anaconda, the bpy looks to work properly, but throws a lot of exception errors for addon utilities. I’ll provide an example of this tomorrow when I’m back at my work desktop. And thank you for that link! I’ve give that a try tomorrow too.

And for the building, I’m surprised you’re using the install_deps.sh as it looks to be only for linux-based builds (docs here). When I was working on my mac-mini, I was following the mac instructions that do not involve install_deps.sh (docs here). Both of these links are for the full python installation, where I’m also following the BlenderAsPyModule directions that are not os-specific.

My build is also failing with a numpy error, but not sure if it’s the same problem as you. Honestly, I’m new to building apps and not sure how to read your build instructions file.

Try disable WITH_OPENMP (that’s what omp stands for).

@TylerGubala
Alright, so down below is the list of import errors that bpy prints. After reading through your ‘Importing Addons’ github page, it looks like all the errors are from the GUI addons, which you already had figured out! So despite all of these errors/warnings, my script still gets past ‘import bpy’ and I can still use basic bpy functionality (e.g. bpy.ops) along with the addon. The mistake I had was with activating the addon properly - I mistakenly thought the init of each addon would activate functionality, so I wasn’t using addon_utils.enable(). I guess I can just ignore the warnings at this point because my script is working as intended.

So at least kitsune.one’s anaconda download is working for me. They have the bpy module from Blender 2.80 available on Mac too if you’re interested. I still wish there was an official anaconda channel for this though - as linux isn’t available from kitsune.one’s, yet their channel still has 1,300 downloads. I also just realized that you manage the bpy 1.2.3 (link)! Are you attempting to update your prebuilt packages?

-Jack

> import bpy
> 
> 
> 
> 
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\bpy\utils\__init__.py", line 93, in _test_import
>     mod = __import__(module_name)
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\startup\bl_ui\__init__.py", line 212, in <module>
>     bpy.utils.register_class(UI_UL_list)
> AttributeError: expected UIList, UI_UL_list class to have an "bl_idname" attribute
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\bpy\utils\__init__.py", line 176, in register_module_call
>     register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\startup\bl_operators\__init__.py", line 68, in register
>     register_class(cls)
> AttributeError: expected Menu, WM_MT_operator_presets class to have an "bl_idname" attribute
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\bpy\utils\__init__.py", line 176, in register_module_call
>     register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\startup\keyingsets_builtins.py", line 677, in register
>     register_class(cls)
> AttributeError: expected KeyingSetInfo, BUILTIN_KSI_LocRot class to have an "bl_idname" attribute
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\bpy\utils\__init__.py", line 176, in register_module_call
>     register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\startup\nodeitems_builtins.py", line 475, in register
>     nodeitems_utils.register_node_categories('SHADER', shader_node_categories)
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\nodeitems_utils.py", line 130, in register_node_categories
>     bpy.utils.register_class(menu_type)
> AttributeError: expected Menu, NODE_MT_category_SH_INPUT class to have an "bl_idname" attribute
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_scene_3ds\\__init__.py'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_scene_fbx\\__init__.py'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_anim_bvh\\__init__.py'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_mesh_ply\\__init__.py'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_scene_obj\\__init__.py'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_scene_3ds\__init__.py", line 151, in register
>     bpy.types.INFO_MT_file_import.append(menu_func_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_scene_fbx\__init__.py", line 644, in register
>     bpy.types.INFO_MT_file_import.append(menu_func_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_anim_bvh\__init__.py", line 224, in register
>     bpy.types.INFO_MT_file_import.append(menu_func_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_mesh_ply\__init__.py", line 193, in register
>     bpy.types.INFO_MT_file_import.append(menu_func_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_scene_obj\__init__.py", line 333, in register
>     bpy.types.INFO_MT_file_import.append(menu_func_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_scene_x3d\\__init__.py'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_mesh_stl\\__init__.py'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_mesh_uv_layout\\__init__.py'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\io_curve_svg\\__init__.py'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_scene_x3d\__init__.py", line 175, in register
>     bpy.types.INFO_MT_file_import.append(menu_func_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_mesh_stl\__init__.py", line 262, in register
>     bpy.types.INFO_MT_file_import.append(menu_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_mesh_uv_layout\__init__.py", line 238, in register
>     bpy.types.IMAGE_MT_uvs.append(menu_func)
> AttributeError: 'RNA_Types' object has no attribute 'IMAGE_MT_uvs'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\io_curve_svg\__init__.py", line 72, in register
>     bpy.types.INFO_MT_file_import.append(menu_func_import)
> AttributeError: 'RNA_Types' object has no attribute 'INFO_MT_file_import'
> Exception in module register(): 'C:\\Users\\jacks\\Anaconda3\\envs\\blender_env\\2.79\\scripts\\addons\\cycles\\__init__.py'
> Traceback (most recent call last):
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\modules\addon_utils.py", line 350, in enable
>     mod.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\cycles\__init__.py", line 132, in register
>     ui.register()
>   File "C:\Users\jacks\Anaconda3\envs\blender_env\2.79\scripts\addons\cycles\ui.py", line 1847, in register
>     bpy.types.RENDER_PT_render.append(draw_device)
> AttributeError: 'RNA_Types' object has no attribute 'RENDER_PT_render'

I had to disable Open MP and Audaspace in order for the Python module to build properly on MacOS.

  • OpenMP causes “undefined symbols for x86_64” in multiple Ceres locations
  • Audaspace causes Numpy include issues despite install_deps.sh clearly showing that Numpy is installed

I feel strange about this requirement though. Open MP is for parallelism, correct? Audaspace is the audio library if I’m not mistaken.

Is there any chances that I could resolve those build errors and get a “complete” bpy.so, so to speak?

Here was my build script (post installation of Python and CMake) for those interested:

export PATH="/Applications/CMake.app/Contents/bin":"$PATH"
echo PATH="/Applications/CMake.app/Contents/bin":"\$PATH" >> ~/.profile
echo PATH="/Applications/CMake.app/Contents/bin":"\$PATH" >> ~/.bash_profile
mkdir .blenderpy
cd .blenderpy
mkdir master
cd master
git clone http://git.blender.org/blender.git
cd blender
make update
cd ..
mkdir build_bpy_darwin_custom
cd build_bpy_darwin_custom
cmake ../blender -DWITH_PLAYER=OFF -DWITH_PYTHON_INSTALL=OFF -DWITH_PYTHON_MODULE=ON -DWITH_OPENMP=OFF -DWITH_AUDASPACE=OFF
make install

@jacksund Yes

It should be possible to fix audaspace, although this is disabled in:

build_files/cmake/config/bpy_module.cmake (now noted at https://wiki.blender.org/wiki/Building_Blender/Other/BlenderAsPyModule).


As for OpenMP, yes it is for parallelism however we’re moving away from this since it has problems on some platforms, so you don’t miss out of much by disabling it.
This worked on Linux last I tested, so this is likely a macOS spesific issue.

Wile resolving this issue on macOS would be good, the python-module feature is experimental so getting all configurations working isn’t a priority.

For now we could just disable OpenMP for macOS so others don’t have to run into the same problems as you did (edit committed).

Okay, the explanation and rationale make sense. I just wanted to let you know anyhow.

Thanks again!

Actually I get a segmentation fault when I import bpy in this manner.

Did you manage to get this working?

If it’s crashing you could try disable all options starting with WITH_, then narrow down whats causing the crash. Running in a debugger might show the issue too.


Otherwise we could define this as unsupported with an error if macOS developers try and build it.

I’ll try both. I’m learning lots about MacOS. Do you have a recommended debug procedure? Any command line tools I should look into? I am usually ssh into my mac mini.


I tried lldb but am not sure what the results mean. Unfortunately I’m not used to looking at these types of plaintext debug frames.

Developer mode is now enabled.
tylergubala@Tylers-Mac-mini .lldb % lldb -f ~/Code/Python/BlenderpyTest/venv/bin/python3 -- ~/Code/Python/BlenderpyTest/tests/import_test.py
(lldb) target create "/Users/tylergubala/Code/Python/BlenderpyTest/venv/bin/python3"
Current executable set to '/Users/tylergubala/Code/Python/BlenderpyTest/venv/bin/python3' (x86_64).
(lldb) settings set -- target.run-args  "/Users/tylergubala/Code/Python/BlenderpyTest/tests/import_test.py"
(lldb) r
Process 44084 launched: '/Users/tylergubala/Code/Python/BlenderpyTest/venv/bin/python3' (x86_64)
Process 44084 stopped
* thread #2, stop reason = exec
    frame #0: 0x0000000100006000 dyld`_dyld_start
dyld`_dyld_start:
->  0x100006000 <+0>: popq   %rdi
    0x100006001 <+1>: pushq  $0x0
    0x100006003 <+3>: movq   %rsp, %rbp
    0x100006006 <+6>: andq   $-0x10, %rsp
Target 0: (Python) stopped.
(lldb) thread continue
Resuming thread 0x91778 in process 44230
Process 44230 resuming
Process 44230 stopped
* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x0000000101a2a063 Python`PyModule_Create2 + 35
Python`PyModule_Create2:
->  0x101a2a063 <+35>: movq   0x10(%rax), %rdi
    0x101a2a067 <+39>: callq  0x101adf820               ; _PyImport_IsInitialized
    0x101a2a06c <+44>: testl  %eax, %eax
    0x101a2a06e <+46>: je     0x101a2a084               ; <+68>
Target 0: (Python) stopped.
(lldb) thread continue
Resuming thread 0x91778 in process 44230
Process 44230 resuming
Process 44230 stopped
* thread #2, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x10)
    frame #0: 0x0000000101a2a063 Python`PyModule_Create2 + 35
Python`PyModule_Create2:
->  0x101a2a063 <+35>: movq   0x10(%rax), %rdi
    0x101a2a067 <+39>: callq  0x101adf820               ; _PyImport_IsInitialized
    0x101a2a06c <+44>: testl  %eax, %eax
    0x101a2a06e <+46>: je     0x101a2a084               ; <+68>
Target 0: (Python) stopped.

Just tried with faulthandler, hope this helps somewhat:

tylergubala@Tylers-Mac-mini build_bpy_darwin_nowith % ~/Code/Python/BlenderpyTest/venv/bin/python3 ~/Code/Python/BlenderpyTest/tests/import_test.py
Fatal Python error: Segmentation fault

Current thread 0x000000010f92dd40 (most recent call first):
  File "<frozen importlib._bootstrap>", line 219 in _call_with_frames_removed
  File "<frozen importlib._bootstrap_external>", line 1043 in create_module
  File "<frozen importlib._bootstrap>", line 583 in module_from_spec
  File "<frozen importlib._bootstrap>", line 670 in _load_unlocked
  File "<frozen importlib._bootstrap>", line 967 in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 983 in _find_and_load
  File "/Users/tylergubala/Code/Python/BlenderpyTest/tests/import_test.py", line 11 in <module>
zsh: segmentation fault  ~/Code/Python/BlenderpyTest/venv/bin/python3

Maybe it would be prudent to look at what some other folks are getting @ideasman42, I have some output being posted over on github where I am trying to aggregate build issues.

Actually, my build environment seemed to be just messed up. I’ve got the build working but now I can’t import bpy due to the scripts dir not being found in my venv.

Still looking though…

>>> import sys
>>> sys.executable
'/Users/tylergubala/Code/Python/BlenderpyTest/venv/bin/python3'
>>> import bpy
Color management: using fallback mode for management
Color management: Error could not find role data role.
BLT_lang_init: 'locale' data path for translations not found, continuing
Color management: scene view "Filmic" not found, setting default "Standard".
bpy: couldn't find 'scripts/modules', blender probably wont start.
Freestyle: couldn't find 'scripts/freestyle/modules', Freestyle won't work properly.
ModuleNotFoundError: No module named 'bpy_types'
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/tylergubala/Code/.blenderpy/master/blender/source/blender/python/intern/bpy_rna.c:7086 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/tylergubala/Code/.blenderpy/master/blender/source/blender/python/intern/bpy_rna.c:7086 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/tylergubala/Code/.blenderpy/master/blender/source/blender/python/intern/bpy_rna.c:7086 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/tylergubala/Code/.blenderpy/master/blender/source/blender/python/intern/bpy_rna.c:7086 pyrna_srna_ExternalType: failed to find 'bpy_types' module
ModuleNotFoundError: No module named 'bpy_types'
ERROR (bpy.rna): /Users/tylergubala/Code/.blenderpy/master/blender/source/blender/python/intern/bpy_rna.c:7086 pyrna_srna_ExternalType: failed to find 'bpy_types' module
F1110 00:13:22.693626 375492032 utilities.cc:322] Check failed: !IsGoogleLoggingInitialized() You called InitGoogleLogging() twice!
*** Check failure stack trace: ***
    @        0x11ba8e7df
    @        0x11ba8af39
    @        0x11ba9236c
    @        0x11a8bbfee
    @        0x11679caad
    @        0x116ae92f7
    @        0x10d23ec7c
    @        0x10d242866
    @        0x10d2fa960
    @        0x10d2f6273
    @        0x10d2f5a79
    @        0x10d216ba8
    @        0x10d216881
    @        0x10d2d2c6f
    @        0x10d2d6363
    @        0x10d216581
    @        0x10d2d5812
    @        0x10d2d27dd
    @        0x10d2169f0
    @        0x10d2d5812
    @        0x10d2d27c3
    @        0x10d2169f0
    @        0x10d2d5812
    @        0x10d2d287e
    @        0x10d2169f0
    @        0x10d2d5812
    @        0x10d2d287e
    @        0x10d2169f0
    @        0x10d2d5812
    @        0x10d2d287e
    @        0x10d2169f0
    @        0x10d215fe4
zsh: abort      python3

Maybe this is related to osx_resources?

That did it.

The documentation is wrong on the Wiki under OSX installation

It says

cp -R ./bin/2.81 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/

When it should say

mkdir /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/Resources

cp -R ./bin/2.81 /Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/Resources

Or

mkdir <PATH_TO_VENV>/lib/python3.7/Resources

cp -R ./bin/2.81 <PATH_TO_VENV>/lib/python3.7/Resources