Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JyniEclipse设置_Eclipse_Numpy_Jython_Jyni - Fatal编程技术网

JyniEclipse设置

JyniEclipse设置,eclipse,numpy,jython,jyni,Eclipse,Numpy,Jython,Jyni,我在Eclipse中有以下Java文件 package java_python_tutorial; import org.python.core.PyInstance; import org.python.util.PythonInterpreter; public class MainJython { public static void main(String[] args) { PythonInterpreter python = new PythonInterp

我在Eclipse中有以下Java文件

package java_python_tutorial;
import org.python.core.PyInstance;
import org.python.util.PythonInterpreter;

public class MainJython {
    public static void main(String[] args) {
        PythonInterpreter python = new PythonInterpreter();
        python.execfile("pytest/test_np.py");
//      PyInstance test = (PyInstance) python.eval("Test()");
//      test.invoke("printArr");
        python.close();
    }
}
如果我只包括Jython JAR,运行该文件将导致Python中名为numpy的
ImportError:no模块。我试图通过在我的项目构建路径中包含JyNI JAR来解决这个问题,但现在运行该文件会出现以下错误:

Exception in thread "main" java.lang.NoClassDefFoundError: org/python/modules/_weakref/ReferenceBackendFactory
    at java.lang.Class.getDeclaredConstructors0(Native Method)
    at java.lang.Class.privateGetDeclaredConstructors(Class.java:2671)
    at java.lang.Class.getConstructor0(Class.java:3075)
    at java.lang.Class.newInstance(Class.java:412)
    at org.python.core.PySystemState.initialize(PySystemState.java:1015)
    at org.python.core.PySystemState.initialize(PySystemState.java:947)
    at org.python.core.PySystemState.initialize(PySystemState.java:930)
    at org.python.core.PySystemState.initialize(PySystemState.java:925)
    at org.python.core.PySystemState.initialize(PySystemState.java:920)
    at org.python.core.PySystemState.initialize(PySystemState.java:916)
    at org.python.core.ThreadStateMapping.getThreadState(ThreadStateMapping.java:32)
    at org.python.core.Py.getThreadState(Py.java:1440)
    at org.python.core.Py.getThreadState(Py.java:1436)
    at org.python.core.Py.getSystemState(Py.java:1456)
    at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:105)
    at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:94)
    at org.python.util.PythonInterpreter.<init>(PythonInterpreter.java:71)
    at java_python_tutorial.MainJython.main(MainJython.java:7)
Caused by: java.lang.ClassNotFoundException: org.python.modules._weakref.ReferenceBackendFactory
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 18 more

请分享您正在使用的JyNI、Jython和NumPy的版本。缺少的类让我怀疑使用了Jython2.7.0,但JyNI需要2.7.1。在JyNI alpha 4之前不支持NumPy,即使是在JyNI alpha 4之前,NumPy也仅在NumPy 1.12和1.13系列中受支持。如果正确的版本没有修复它,请分享你如何配置类路径和pythonpath。你修复了吗?我也有同样的问题,不幸的是没有。我最终使用了不同的解决方案。
import numpy as np

class TestNP(object):
    def __init__(self):
        self.arr = np.array([[1,2,3],[4,5,6]])

    def printArr(self):
        print(self.arr)