To import and use dna_viewer in your scripts, you must configure the Python path and environment variables so the interpreter can locate the library and its dependencies.
If you are running scripts within Maya, ensure ROOT_DIR is set to the absolute path of the repository root instead of using the relative path logic provided below.
Key steps performed by the setup code:
- Determines the correct library directory (
LIB_DIR) based on the operating system (win32 or linux). - Appends
LIB_DIR to the MAYA_PLUG_IN_PATH environment variable to ensure Maya can find the necessary plugins. - Appends both the repository root and the library directory to
sys.path.
from sys import path as syspath, platform
from os import environ, path as ospath
# Note: If using Maya, replace this with an absolute path to the repo root
ROOT_DIR = fr"{ospath.dirname(ospath.abspath(__file__))}/..".replace("\\", "/")
ROOT_LIB_DIR = fr"{ROOT_DIR}/lib"
if platform == "win32":
LIB_DIR = f"{ROOT_LIB_DIR}/windows"
elif platform == "linux":
LIB_DIR = f"{ROOT_LIB_DIR}/linux"
else:
raise OSError("OS not supported, please compile dependencies and add value to LIB_DIR")
if "MAYA_PLUG_IN_PATH" in environ:
separator = ":" if platform == "linux" else ";"
environ["MAYA_PLUG_IN_PATH"] = separator.join([environ["MAYA_PLUG_IN_PATH"], LIB_DIR])
else:
environ["MAYA_PLUG_IN_PATH"] = LIB_DIR
syspath.append(ROOT_DIR)
syspath.append(LIB_DIR)