JPype won't compile properly

坚强是说给别人听的谎言 提交于 2020-01-24 14:19:05

问题


So I am having trouble compiling a very simple python script using JPype.

My code goes like:

from jpype import *
startJVM(getDefaultJVMPath(), "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()

and when I run it I receive an error saying:

Traceback (most recent call last):   File "test.py", line 2, in
<module>
    startJVM(getDefaultJVMPath(), "-ea")   File "/usr/lib/pymodules/python2.7/jpype/_core.py", line 44, in startJVM
    _jpype.startup(jvm, tuple(args), True) RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error =
/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared
object file: No such file or directory at
src/native/common/include/jp_platform_linux.h:45

I'm stuck and I really need help. Thanks!


回答1:


I had the same problem

RuntimeError: Unable to load DLL [/usr/java/jre1.5.0_05/lib/i386/client/libjvm.so], error = /usr/java/jre1.5.0_05/lib/i386/client/libjvm.so: cannot open shared object file: No such file or directory at src/native/common/include/jp_platform_linux.h:45

In my case wrong JAVA_HOME path was set

/profile/etc

export JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
PATH="$JAVA_HOME/bin:$PATH"
export PATH



回答2:


The work around is to define the full path directly in the call to the JVM:

from jpype import *
startJVM('/Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/MacOS/libjli.dylib', "-ea", "-Djava.class.path=/tmp/Jpype/sample")
java.lang.System.out.println("Hello World!!")
shutdownJVM()

Original text:

Similar issues when trying to run JPype on MacOS El Capitan. I could not figure out how to coax the _darwin.py code finding the correct JVM location, despite the JAVA_HOME system variable being set properly.

Caveat cursor, trying to run the above code in the Spyder IPython console did not produce any output, but the normal Console would.



来源:https://stackoverflow.com/questions/15029760/jpype-wont-compile-properly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!