Where do I put the Python packages my addon imports so Blender can find them? (There are some questions on this topic already but I can't find what I'm doing wrong.)
It works fine on my Linux system where I can install the dependencies to a standard Python path. But I understand Blender often comes with its own Python installation, and besides I want a way to bundle all the code together for a one-click install from zip file.
First I tried making it into a single package, that is scripts/addons/my_addon/
containing my code in __init__.py
and subdirectories for the dependencies. Blender finds __init__.py
fine, but import
fails even though the modules are right there in the same place.
So I tried putting the dependencies in scripts/addons/modules/
, though I don't like that because they could clobber different versions installed by another addon, and they stay there even if the user removes my addon through User Preferences. But this still isn't working.
For example: "six" is a module that helps with python 2/3 portability; it's contained in a single file six.py
. From the Blender Python console on Windows:
>>> print(sys.path[-1])
C:\Users\jwelsh\AppData\Roaming\Blender Foundation\Blender\2.70\scripts\addons\modules
>>> print(imp.find_module('six')[1])
C:\Users\jwelsh\AppData\Roaming\Blender Foundation\Blender\2.70\scripts\addons\modules\six.py
>>> import six
Traceback (most recent call last):
File "<blender_console>", line 1, in <module>
ImportError: No module named 'six'
strace
to find which paths are searched for Python module loading. you could try find anstrace
equivalent for Windows. $\endgroup$