Tag: libraries

How to install python libs in Blender (part 1)

EDIT 2020: This series is now obsolete since Blender 2.80. Please see this answer on StackExchange. Here is a possible function to install modules inside Blender, provided you can modify the Blender directory:

import subprocess

def install_pip_dep(module_name):
    python_path = bpy.app.binary_path_python
    subp = subprocess.run([python_path, "-m", "ensurepip"])
    if subp.returncode != 0:
        return False
    subp = subprocess.run([python_path, "-m", "pip", "install", module_name])
    if subp.returncode != 0:
        return False
    return True

if __name__ == '__main__':
    install_pip_dep("triangle")

In this article, we share some tips to install third-party python libraries for your scripts and add-ons. This is the easy way, when the library exists on repositories accessible to package managers such as pip.