[英]Using a python module in Java through Jython but I am very new to paths and how to configure them
package dbase;
导入 org.python.util.PythonInterpreter;
导入 java.awt.BorderLayout;
导入 javax.swing.JFrame;
导入 javax.swing.JList;
导入 javax.swing.JTextField;
导入 org.jdesktop.swingx.autocomplete.AutoCompleteDecorator;
导入 org.jdesktop.swingx.autocomplete.ObjectToStringConverter;
公开课主审{
公共静态无效主(字符串 [] args){
JFrame mf= new JFrame("Main");
JList l = new JList(listn); //数据类型为Object[]
mf.setVisible(true);
JTextField tf1=new JTextField("名称");
BorderLayout bl=新的BorderLayout();
mf.setLayout(bl);
AutoCompleteDecorator.decorate(l, tf1,ObjectToStringConverter.DEFAULT_IMPLEMENTATION);
mf.add(tf1, bl.north);
PythonInterpreter pyInterp = new PythonInterpreter();
pyInterp.exec("from mpt import p3");
}
}
这段代码总是告诉我没有名为 mpt 的模块。 我正在使用 eclipse,mpt 是 python 项目中的一个 python 模块。 请告诉我如何使用 python 模块。
如果您通过类路径指向“mpt”模块(假设为 mpt.py),则应该可以找到它。
示例:Project->Properties->Java Build Path->Add External Class Folder(指向模块位置)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.