How to use the site-packages folder to share Python modules/packages between sketches

I have heard of this many times but @berin was the one friend who made me try it at last.

Inside yoursketchbook/libraries folder (Processing/libraries on Mac and Windows) you can have a site-packages folder containing “Python packages” with modules (.py files) that can be imported by any of your sketches (without having to add them as tabs).

libraries/site-packages/my_lib   
                         |_   __init__.py  (can be an empty file) 
                         |_   a_module.py   (name them as you wish...)
                         |_   b_module.py

Then you can use inside your sketch:

from my_lib import a_module, b_module
# or any other normal Python import-happy ways of importing stuff 
from my_lib.a_module import *   
from my_lib import a_module as amod
from my_lib.b_module import my_great_function, MyClass   

I hope I have described this correctly and that it may be useful to other people.

2 Likes