首页 > 解决方案 > jython 中的 Pythonnet

问题描述

我正在尝试通过 jython 从 java 执行用 python 编写的类和函数。它运行良好,直到在 python 中我们遇到“import clr”,即 pythonnet。

谁能告诉如何使用 jython 或任何其他使用“import clr”的东西从 java 运行 python 脚本

蟒蛇代码:file.py

import clr

使用 jython 的 java 代码:

Properties props = new Properties();
Properties preprops = System.getProperties();
PythonInterpreter.initialize(preprops, props, new String[0]);
PythonInterpreter interp = new PythonInterpreter();
interp.exec("<absoulute_path//file.py>");

错误:

Exception in thread "main" Traceback (most recent call last):
  File "<string>", line 3, in <module>
ImportError: No module named clr

标签: javapythonjythonpython.net

解决方案


Jython 不提供 Python C API,因此您无法通过它构建和使用 Python.NET。


推荐阅读