Unable to compile Blender 2.8 as Python module

python

#1

I am trying to compile Blender 2.8 as Python module but I get errors in Python after a successful compilation. Here are the errors:

import bpy
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_scene_3ds’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_scene_fbx’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_anim_bvh’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_mesh_ply’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_scene_obj’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_scene_x3d’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_mesh_stl’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_mesh_uv_layout’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_curve_svg’
Traceback (most recent call last):
File “/usr/local/lib/python3.6/dist-packages/2.80/scripts/modules/addon_utils.py”, line 351, in enable
mod = import(module_name)
ModuleNotFoundError: No module named ‘io_scene_gltf2’

I install the dependencies and do make update before compiling the Master branch and here’s the CMake flags that I use for building:

-DCMAKE_INSTALL_PREFIX=/usr/local/lib/python3.6/dist-packages
-DWITH_PYTHON_INSTALL=OFF
-DWITH_PYTHON_MODULE=ON
-DPYTHON_ROOT_DIR=/usr/local
-DPYTHON_SITE_PACKAGES=/usr/local/lib/python3.6/dist-packages
-DPYTHON_INCLUDE=/usr/include/python3.6/
-DPYTHON_INCLUDE_DIR=/usr/include/python3.6m
-DPYTHON_LIBRARY=/usr/lib/python3.6/config-3.6m-x86_64-linux-gnu/libpython3.6.so
-DPYTHON_VERSION=3.6
-DWITH_INSTALL_PORTABLE=OFF
-DWITH_CYCLES_EMBREE=OFF
-DWITH_CYCLES=ON
-DWITH_CYCLES_DEVICE_CUDA=ON
-DWITH_OPENSUBDIV=ON
-DWITH_OPENAL=OFF
-DWITH_CODEC_AVI=ON
-DWITH_MOD_OCEANSIM=ON
-DWITH_CODEC_FFMPEG=ON
-DWITH_SYSTEM_GLEW=ON
-DWITH_FFTW3=ON
-DWITH_OPENCOLORIO=ON
-DWITH_GAMEENGINE=OFF
-DWITH_PLAYER=OFF
-DWITH_INTERNATIONAL=OFF
-DCMAKE_BUILD_TYPE:STRING=Release

Am I doing something wrong?


#2

Have a look at the solutions provided here:


#3

The problem was solve by doing the followings and then compiling:

git submodule update --remote
git submodule update --init --recursive
git submodule foreach git checkout master
git submodule foreach git pull --rebase origin master
make update


#4

For blender2.7, i did the following …
(assuming the blender source repo is already cloned)

  1. git checkout blender2.7
  2. git submodule update --init (recursive should be optional here since the blender submodules are not nested)
  3. if that foreach thing doesnt work you could do it manually…

for locale:
go to release/datafiles/locale

  1. git status (optional, but good to check the current status of that submodule directory)
  2. git checkout blender2.7
  3. git fetch (optional step, but i prefer it since it shows the changes before adding them to the local branch)
  4. git pull (rebase is only necessary if you have local changes in the submodule and want to add your local commits on top of the fetched ones, to have a clean history…)

for addons:
go to release/scripts/addons and the same 4 steps as for locale

for addons_contrib:
go to release/scripts/addons_contrib and the same 4 steps as for locale

for tools:
go to source/tools

  1. git status
  2. git checkout master (because there seems to be no blender2.7 branch there)
  3. git fetch
  4. git pull

you can optionally verify with git status whether the correct branches are checked out

Then… in the blender source directory:

make bpy

(this will generate a build_linux_bpy folder and set up the cmake stuff)
You could try to pass some CMAKE arguments there, but i prefer always to do it via cmake gui.

If compilation succeeds you end up with a bin folder in build_linux_bpy and a bpy.so file.
Now, you can disable WITH_MEM_JEMALLOC and hit Configure, Generate.
In the build_linux_bpy directory you can then type

make install

This should rebuild and install the bpy.so to PYTHON_SITE_PACKAGES. (this is configurable via cmake-gui for example, too)

For me it points to:

<blender_dev>/lib/linux_x86_64/python/lib/python3.7/site-packages

. There i found the bpy.so.

In my case I didnt install the bpy.so globally, but tested it with the python3.7m executable in

<blender_dev>/lib/linux_x86_64/python/bin

like ./python3.7m which opens a python interpreter (3.7)

there i just did “import bpy” and it worked.

What i did not do was installing the bpy.so as global python module… so it becomes available for the distro’s main python 3.7 interpreter.

Edit: just noticed: the 2.79 folder with scripts, addons etc is being installed under PYTHON_SITE_PACKAGES too, means bpy.so seems to expect that directory structure.
So i have here e.g.

<blender_dev>/lib/linux_x86_64/python/lib/python3.7/site-packages/2.79/scripts

etc… hmm maybe this shouldnt be named “dist-packages”