所以我在使用JPype编译一个非常简单的python脚本时遇到了麻烦。
我的代码如下:
from jpype import *
startJVM(getDefaultJVMPath(), "-ea")
java.lang.System.out.println("hello world")
shutdownJVM()
当我运行它时,我收到一条错误说:
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
我被困住了,我真的需要帮助。谢谢!
答案 0 :(得分:1)
我遇到了同样的问题
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
在我的情况下,设置了错误的JAVA_HOME路径
/简档/等
export JAVA_HOME
JAVA_HOME=/usr/lib/jvm/java-6-openjdk-amd64
PATH="$JAVA_HOME/bin:$PATH"
export PATH
答案 1 :(得分:1)
解决方法是直接在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()
原文:
尝试在MacOS El Capitan上运行JPype时出现类似问题。我可以 没弄清楚如何哄骗_darwin.py代码找到正确的JVM 尽管正确设置了JAVA_HOME系统变量,但仍然是位置。
警告游标,试图在Spyder IPython控制台中运行上面的代码没有产生任何输出,但正常的控制台会。