gpt4 book ai didi

java - 找不到 Jython 类

转载 作者:行者123 更新时间:2023-11-30 06:34:42 25 4
gpt4 key购买 nike

我编写了一个名为 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)

最佳答案

org.python.util 包应该存在于您缺少的 jython.jar 中

您可以从jython下载

如果存在,请将其添加到您的命令中(而不是 javac Jug.java)

java -cp jython.jar:. Jug

关于java - 找不到 Jython 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45399799/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com