Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Install blender as a module with python 3.5 and pyenv

#Install blender as a module with python 3.5 and pyenv

Tested on Ubuntu 14.04.

Setting up a new python environment using pyenv

Follow instructions from here.

Installing boost

Follow instructions from here.

Installing blender as a module

The instructions are mostly the same as the official installation instructions except for a few modifications specified below.

Install the python dependecies using pip:

pip install numpy
pip install requests

When blender is build as a module, the blender binary doesn't get built. So, first build blender as normal following these instructions. Run to generate the cmake options. For example, build all libraries except for opensubdivision, opencollada and ffmpeg:

./blender/build_files/build_environment/ --source ./ --threads=4 --with-all --skip-osd --skip-ffmpeg

When using cmake, use the following python options (in addition to any other options returned from the command above that you need):

cmake -DPYTHON_VERSION=3.5 -DPYTHON_ROOT_DIR=~/.pyenv/versions/3.5.1 ../blender

Make sure to build it and install it:

make -j4
make install

This should have created the blender binary bin/blender. Now, build blender as a module as described in the original post (in addition to any other options):


Build it an install it:

make -j4
make install

This should have created the python library bin/

Copy link

I am trying to compile Blender to get the Python library. Everything goes well until compilation gets to 100% and I get an error like this:

[100%] Building C object source/creator/CMakeFiles/blender.dir/buildinfo.c.o
Linking CXX shared module ../../bin/
/usr/bin/ error: /opt/lib/python-3.5/lib/libpython3.5m.a(abstract.o): requires dynamic R_X86_64_PC32 reloc against 'PyType_IsSubtype' which may overflow at runtime; recompile with -fPIC

How can I resolve this issue?

Copy link

lvxejay commented Feb 17, 2018

You can fix this by rebuilding python as a shared library. Example using pyenv here

env PYTHON_CONFIGURE_OPTS='--enable-shared' pyenv install -v 3.5.4
pyenv rehash
pyenv shell 3.5.4
python -V


cmake -DCMAKE_CXX_FLAGS="-fPIC" -DCMAKE_C_FLAGS="-fPIC" ../blender

Then make again

sudo make -j4
sudo make install -j4

Copy link

davidwessman commented Feb 20, 2018

Thank you for your guide @alexlee-gk and your addition @lvxejay.

I managed to create the python library, but not sure how I make my python installation able to access it globally.
Right now I compiled it in ~/bin/blender/build, should I copy any files to my pyenv site-packages or should I link it somehow?

Just realized I forgot to add the options mentioned in the Local install part of official instructions.
Pointing to my own sites-packages fixed it for me!

Copy link

@davidwessman I am stuck on the same step you were in Feb 20, except the official instructions have been taken down. Do you recall how to point to your site-packages? Trying to copy just into my pyenv's site packages for the python distribution I used (anaconda3-5.2.0) I am able to import bpy, but immediately have errors thrown because it can't find any of the other dependencies.

Copy link

danong commented Aug 9, 2018

@nfehrenbach I don't know the answer to your exact problem but you can still access the instructions at the old wiki:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment