Search code examples
python-3.xlinuxdeep-learninggoogle-colaboratoryblender

How to use Blender in google colab?


I am trying to implement this reporsitory on Google colab. It requires to install blender and link it to /usr/local/bin/blender.

Their ReadMe states- (Please install Blender 2.79. There is no need to build from source, you can simply download the prebuilt binary and link it at /usr/local/bin/blender.)

But I am not getting how to do it on Google colab. Any help would be appreciated.


Solution

  • To start, Google Collab uses IPython which is an interactive python shell (so to speak). IPython allows for shell assignment which means you can execute shell commands from it and that is also possible in Google Collab.

    All you need to do is to download blender and then link it to /usr/local/bin/blender. Except there is a known issue related to libtcmalloc that needs to be taken into account (you will have to apply the fix regardless whether you use CPU or GPU). So the end script would look like this:

    import os
    os.environ["LD_PRELOAD"] = ""
    
    !apt remove libtcmalloc-minimal4
    !apt install libtcmalloc-minimal4
    
    os.environ["LD_PRELOAD"] = "/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4.3.0"
    
    !wget https://download.blender.org/release/Blender2.79/blender-2.79-linux-glibc219-x86_64.tar.bz2
    !tar -xf blender-2.79-linux-glibc219-x86_64.tar.bz2
    
    # if you still get any errors regarding LD_PRELOAD you can check whether a good path is applied (if the version of library has not changed)
    !dpkg -L libtcmalloc-minimal4 
    
    !ln -s /content/blender-2.79-linux-glibc219-x86_64/blender /usr/local/bin/blender
    !blender -v
    

    I have managed to properly run blender and got the right version.