[Bf-committers] Issues with building blender as a python module on Linux

Cambell Barton ideasman42 at gmail.com
Fri Sep 13 00:04:59 CEST 2019

Hi Alex,

The old docs have been moved to: 

However they didn't change in any important way. I just double checked 
and this works here.

When running "make install" you should see:

-- Installing: /usr/lib64/python3.7/site-packages/bpy.so

.. as one of the lines of output.

After this, try run:

python -c "import bpy; bpy.ops.wm.save_as_mainfile(filepath='my.blend')"

You should get "my.blend" file created in the current directory.

On 2019-09-12 23:20, Dalai Felinto wrote:
> Hi Alex,
> When building python as a module, you will get a "bpy.so" file. This
> will be in a "bin" folder under your build folder.
> In your case :/home/username/blender-git/build_linux_bpy/bin/bpy.so
> which is not the same you are trying to use from /scripts/modules/bpy
> PS: We need to update the API page. It currently points to a
> non-ported wiki page for the build instructions:
> https://docs.blender.org/api/current/info_tips_and_tricks.html?#blender-as-a-module
> Cheers,
> Dalai
> Em ter, 10 de set de 2019 às 17:02, Alex Delgado
> <alexdel247 at gmail.com> escreveu:
>> Hi,
>> I am not sure if this is the best place to ask this question, but I have
>> been trying to build blender as a python module on my Linux (Debian
>> GNU/Linux 9.9) virtual machine, and I have been having a lot of trouble.
>> I have followed this instructions:
>> https://wiki.blender.org/wiki/Building_Blender/Linux/Ubuntu
>> https://blender.stackexchange.com/questions/126959/how-to-build-blender-as-python-module
>> and have tried with different versions of Blender (2.81 and 2.79) and with
>> different variations in step 2 of installing the dependencies such
>> as install_deps.sh --skip-python --skip-numpy.
>> In step 3 (Compiling blender with CMake) I run the below command in cd
>> ~/blender-git/blender
>> instead of just make. These parameters(except for the ones in blue, is what
>> the output told be to do after running  install_deps.sh .
>>    sudo make bpy -j2 BUILD_CMAKE_ARGS="-U *SNDFILE* -U *PYTHON* -U *BOOST*
>> OSL_ROOT_DIR=/opt/lib/osl -D LLVM_ROOT_DIR=/opt/lib/llvm -D LLVM_STATIC=ON
>> FFMPEG_LIBRARIES='avformat;avcodec;avutil;avdevice;swscale;swresample;lzma;rt;theora;theoradec;theoraenc;vorbis;vorbisenc;vorbisfile;ogg;x264'"
>> After this step, I get a message that blender was successfully built, but
>> then after trying to import bpy, after typing python3 or python in the
>> Linux command like I get this error:
>>>>> import bpyTraceback (most recent call last): File "<stdin>", line 1, in
>> <module> File
>> "/home/username/blender-git/build_linux_bpy/bin/2.79/scripts/modules/bpy/__init__.py",
>> line 38, in <module> from _bpy import types, props, app, data,
>> contextModuleNotFoundError:
>> No module named '_bpy'
>> This is after adding this to my Pythonpath:
>> export
>> PYTHONPATH=$PYTHONPATH:/home/username/blender-git/build_linux_bpy/bin/2.79/scripts/modules:/home/username/blender-git/build_linux_bpy/bin/2.79/scripts/modules/bpy
>> I take the error above to mean that it is trying to run it as an internal
>> blender C module according to this post .
>> https://stackoverflow.com/questions/37187025/blender-python-bpy-init-py-apparently-importing-from-a-non-existent-mod
>> My question is what am I missing here to make this work? Is there a
>> parameter that I am missing when running sudo make bpy? Do I need to do
>> something different in the Pythonpath? Do I need to have a specific version
>> of python in order for this to work? (I have 2.7 and 3.7 that came from the
>> anaconda package).
>> About two years ago I was able to successfully build blender 2.78 as a
>> python module in my windows machine and use it directly from my python
>> interpreter in eclipse. I remember the process being tedious as well, but
>> this time I feel like I have exhausted all the answers from the internet.
>> If anyone has successfully build blender as a python module on linux, and
>> has ran into similar issues as mine and could point me to what I am doing
>> wrong I will greatly appreciate it.
>> Thanks,
>> Alex
>> _______________________________________________
>> Bf-committers mailing list
>> Bf-committers at blender.org
>> https://lists.blender.org/mailman/listinfo/bf-committers
> _______________________________________________
> Bf-committers mailing list
> Bf-committers at blender.org
> https://lists.blender.org/mailman/listinfo/bf-committers

More information about the Bf-committers mailing list