【发布时间】:2015-09-04 16:42:33
【问题描述】:
我正在尝试通过在我的 Java 应用程序中嵌入 Jython 来加载 Python 类。
我目前的代码是
String pythonRoot = Main.class.getResource("/python").getPath(); PySystemState 状态 = 新 PySystemState(); PyObject importer = state.getBuiltins().__getitem__(Py.newString("__import__")); PyObject sysModule = importer.__call__(Py.newString("sys")); 最终 PyString pythonPath = Py.newString(pythonRoot); PyList path = (PyList) sysModule.__getattr__("path"); path.add(pythonPath); PyModule 模块 = (PyModule) importer.__call__(Py.newString("building.blah.again.blah2.Test")); PyObject klass = module.__getattr__(Py.newString("Address")); AddressInterface ai = (AddressInterface) klass.__call__().__tojava__(AddressInterface.class);我尝试访问的类可以在
中找到 /python/building/blah/again/blah2/Test.py而班级的名字是
地址但是,这给了我一个例外
线程“主”ImportError 中的异常:没有名为 blah2 的模块如果我在上面的目录中放置一些文件,像这样
/python/building/blah/again/Test.py这给了我一个例外
线程“主”ImportError 中的异常:没有再次命名模块就好像他在主动拒绝识别包含文件的目录。这可能是什么问题,我该如何解决这个问题?
【问题讨论】: