Skip to content

Instantly share code, notes, and snippets.

@keunhong
Forked from alexlee-gk/install_blender_pyenv.md
Last active March 20, 2020 12:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save keunhong/279c98de28877a3a33a1eb95fa7d56a5 to your computer and use it in GitHub Desktop.
Save keunhong/279c98de28877a3a33a1eb95fa7d56a5 to your computer and use it in GitHub Desktop.
Install blender as a module with python 3.5 and pyenv

Install blender as a module with python 3.7 and pyenv

Instructions WIP

Tested on Ubuntu 18.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 install_deps.sh to generate the cmake options. For example, build all libraries except for opensubdivision, opencollada and ffmpeg:

./blender/build_files/build_environment/install_deps.sh --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.7 -DPYTHON_ROOT_DIR=~/.pyenv/versions/3.7.0 ../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):

cmake \
  -DPYTHON_VERSION=3.7.0 \
  -DPYTHON_ROOT_DIR=$(pyenv prefix) \
  -DCMAKE_INSTALL_PREFIX=$(pyenv prefix)/lib/python3.7/site-packages \
  -DWITH_CYCLES=ON \
  -DWITH_GAMENGINE=OFF \
  -DWITH_IMAGE_HDR=ON \
  -DWITH_IMAGE_OPENEXR=ON \
  -DWITH_IMAGE_TIFF=ON \
  -DWITH_OPENCOLLADA=OFF \
  -DWITH_OPENMP=ON \
  -DWITH_OPENIMAGEIO=ON \
  -DWITH_PYTHON_INSTALL=OFF \
  -DWITH_PYTHON_MODULE=ON \
  -DPYTHON_LIBRARY=$(pyenv virtualenv-prefix)/lib/libpython3.7m.so \
  -DPYTHON_LIBPATH=$(pyenv virtualenv-prefix)/lib \
  -DPYTHON_INCLUDE_DIR=$(pyenv virtualenv-prefix)/include/python3.7m \
  ..

Build it an install it:

make -j4
make install

This should have created the python library bin/bpy.so.

@keunhong
Copy link
Author

cmake \
  -DPYTHON_VERSION=3.6.5 \
  -DPYTHON_ROOT_DIR=$(pyenv prefix) \
  -DCMAKE_INSTALL_PREFIX=$(pyenv prefix)/lib/python3.6/site-packages \
  -DWITH_CYCLES=ON \
  -DWITH_GAMENGINE=OFF \
  -DWITH_IMAGE_HDR=ON \
  -DWITH_IMAGE_OPENEXR=ON \
  -DWITH_IMAGE_TIFF=ON \
  -DWITH_OPENCOLLADA=OFF \
  -DWITH_OPENMP=ON \
  -DWITH_OPENIMAGEIO=ON \
  -DWITH_PYTHON_INSTALL=OFF \
  -DWITH_PYTHON_MODULE=ON \
  -DPYTHON_LIBRARY=$(pyenv virtualenv-prefix)/lib/libpython3.6m.so \
  -DPYTHON_LIBPATH=$(pyenv virtualenv-prefix)/lib \
  -DPYTHON_INCLUDE_DIR=$(pyenv virtualenv-prefix)/include/python3.6m \
  ..

@keunhong
Copy link
Author

On ubuntu 16.04 you need a newer version of clang than is provided.

https://blog.kowalczyk.info/article/k/how-to-install-latest-clang-5.0-on-ubuntu-16.04-xenial-wsl.html

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