I have a custom Python package/module with the following file structure:
package
– __init__.py
– lib1.py
– lib2.py
init.py contains imports for os, random, lib1, and lib2. lib1 contains a class, as does lib2.
In Grasshopper, I add the absolute path of the package directory to sys.path, since it’s currently not located inside the default Rhino scripts folder.
import sys
if "absolute/path/package" not in sys.path:
sys.path.append("absolute/path/package")
import package # works fine!
As already indicated above, I’ve outsourced the importing of modules - like os, random, etc. - that I use frequently in both lib1.py and lib2.py, to __init__.py.
However, when I call classes and their methods in GHPython from lib1.py and lib2.py, I get errors, like global name 'os' is not defined, although I import os in __init__.py?
I’ve also noticed that no Python cache files (.pyc) get created, when I import package in GHPython?
One major inconvenience is that the GHPython component only seems to reflect changes made to the module files, when Rhino is restarted. Simply recomputing the Grasshopper solution doesn’t work. This makes debugging a nightmare! Thanks again.