我写了一个名为jug.java的java文件,它使用了jython和PythonInterpreter;这是代码:
import org.python.util.PythonInterpreter;
import org.python.core.PyObject;
public class Jug{
public void main(String[] args) {
PythonInterpreter interpreter = new PythonInterpreter();
interpreter.exec("import InstaFeed\nAPI=InstaFeed.InstaFeed(someusername, somepassword)");
PyObject someFunc = interpreter.get("API.like(mediaId");
PyObject result = someFunc.__call__(new PyInteger(15));
String realResult = (String) result.__tojava__(String.class);
}
}
当我尝试使用此命令执行它时:
javac Jug.java
发生以下错误:
Jug.java:1: error: package org.python.util does not exist
import org.python.util.PythonInterpreter;
^
Jug.java:2: error: package org.python.core does not exist
import org.python.core.PyObject;
^
Jug.java:6: error: cannot find symbol
PythonInterpreter interpreter = new PythonInterpreter();
^
symbol: class PythonInterpreter
location: class Jug
Jug.java:6: error: cannot find symbol
PythonInterpreter interpreter = new PythonInterpreter();
^
symbol: class PythonInterpreter
location: class Jug
Jug.java:8: error: cannot find symbol
PyObject someFunc = interpreter.get("like");
^
symbol: class PyObject
location: class Jug
Jug.java:9: error: cannot find symbol
PyObject result = someFunc.__call__(new PyInteger(15));
^
symbol: class PyObject
location: class Jug
Jug.java:9: error: cannot find symbol
PyObject result = someFunc.__call__(new PyInteger(15));
^
symbol: class PyInteger
location: class Jug
7 errors
还安装了jython。 我该如何解决这个错误?
更多信息
我已经使用终端安装了jython:
sudo apt install jython
它成功安装了jython。 但每当我尝试从源代码安装它时:
sudo java -jar jython-installer-2.7.0.jar
发生以下错误:
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x00007f0f6e654009, pid=31088, tid=31089
#
# JRE version: OpenJDK Runtime Environment (9.0) (build 9-internal+0-2016-04-14-195246.buildd.src)
# Java VM: OpenJDK 64-Bit Server VM (9-internal+0-2016-04-14-195246.buildd.src, mixed mode, tiered, compressed oops, g1 gc, linux-amd64)
# Problematic frame:
# C [libjava.so+0x1d009] JNU_GetEnv+0x19
#
# Core dump will be written. Default location: Core dumps may be processed with "/usr/share/apport/apport %p %s %c %P" (or dumping to /home/muhammad/Downloads/core.31088)
#
# An error report file with more information is saved as:
# /home/muhammad/Downloads/hs_err_pid31088.log
#
# If you would like to submit a bug report, please visit:
# http://bugreport.java.com/bugreport/crash.jsp
# The crash happened outside the Java Virtual Machine in native code.
# See problematic frame for where to report the bug.
#
Aborted (core dumped)
答案 0 :(得分:1)
包org.python.util应该存在于你缺少的jython.jar中
您可以从jython
下载如果存在,请将其添加到您的命令(而不是javac Jug.java
)
java -cp jython.jar:. Jug