1
$\begingroup$

I am trying to learn Blender to make math animations, and since I expect to use it almost exclusively through the Python api, I am writing a library of utilities as I go: https://github.com/bencbartlett/pyblend I would like to be able to import this library within Blender. I have run the following to install it:

git clone https://github.com/bencbartlett/pyblend.git
/Applications/Blender.app/Contents/Resources/2.93/python/bin/python3.9 -m pip install -e pyblend

If I then run /Applications/Blender.app/Contents/Resources/2.93/python/bin/python3.9 and import pyblend, it imports as expected, but when I open Blender and run import pyblend in the console, I get a ModuleNotFoundError. Strangely, the dependencies for the module which were not previously present (such as matplotlib) are correctly installed, but the module itself is not.

What am I doing wrong and how can I install a local module so that it is importable within Blender?

$\endgroup$
0

1 Answer 1

0
$\begingroup$

If you run this script it will print out all the places Blender (or other instance of Python) looks for scripts:

import sys

print(sys.path)

You can add to this path at runtime if you need to, I have a plugin that has a libs/ folder under its installed folder. There is code like this to add the library path in the folder the plugin file is running from:

import os
import sys
local_module_path=os.path.join(os.path.dirname(os.path.abspath(__file__)),'libs')
if local_module_path not in sys.path:
    sys.path.append(local_module_path)
$\endgroup$

Not the answer you're looking for? Browse other questions tagged .