前言:
作为自动化项目的一部分,需要外部python调用houdini python的hou模块。在测试这部分时,总是遇到 _hou 模块缺失的问题。下面附上解决方案。
(win10,houdini19.0.427,VS Code,Python3.7.8(houdini自带的是3.7.4,暂不确定别的版本是否可行))
1.添加环境:
path:C:\Program Files\Side Effects Software\Houdini 19.0.427\bin
path:C:\Program Files\Side Effects Software\Houdini 19.0.427\python37
PYTHONPATH(这个我是直接在代码里写了添加到环境,所以就没直接添加了):C:\Program Files\Side Effects Software\Houdini 19.0.427\houdini\python3.7libs
2.测试:
新建test.py,新建test.hip包含一个box1_SOP并保存到同一目录下。
#!/usr/bin/python
def enableHouModule():
import sys, os
if hasattr(sys, "setdlopenflags"):
old_dlopen_flags = sys.getdlopenflags()
import DLFCN
sys.setdlopenflags(old_dlopen_flags | DLFCN.RTLD_GLOBAL)
try:
import hou
except ImportError:
sys.path.append("C:\Program Files\Side Effects Software\Houdini 19.0.427\houdini\python3.7libs")
import hou
finally:
if hasattr(sys, "setdlopenflags"):
sys.setdlopenflags(old_dlopen_flags)
enableHouModule()
import hou
if __name__ == "__main__":
try:
hou.hipFile.load("test.hip")
network = hou.node("/obj")
for eachOBJ in network.children():
print(eachOBJ)
except hou.LoadWarning as e:
print(e)
如同,3.7.8的解释器成功打印出了“box1”