Hi,
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?
Any ideas what I’m missing here?
Thanks.
9 posts - 4 participants