javabridge.jutil.JVMNotFoundError:找不到Java虚拟机

问题描述 投票:0回答:1

我想在我的python代码中使用Weka,所以我根据https://fracpete.github.io/python-weka-wrapper/install.html安装java-wrapper python(2.7.16),我的java版本是:java version“1.8.0_201”Java(TM)SE Runtime Environment(build 1.8.0_201) -b09)Java HotSpot(TM)64位服务器VM(内置25.201-b09,混合模式)

另外,我根据https://troubleshooter.xyz/wiki/fix-java-virtual-machine-jvm-not-found-error/将JDK路径添加到用户变量PATH

但它会引发错误:

   >>>import os
   >>>import traceback
   >>>import weka.core.jvm as jvm
   Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
   File "C:\Python27\lib\site-packages\weka\core\jvm.py", line 17, in 
   <module>
    import javabridge
   File "C:\Python27\lib\site-packages\javabridge\__init__.py", line 38, in 
    <module>
    from .jutil import start_vm, kill_vm, vm, activate_awt, deactivate_awt
    File "C:\Python27\lib\site-packages\javabridge\jutil.py", line 151, in 
    <module>
    os.pathsep + os.path.join(find_javahome(), "bin")
    File "C:\Python27\lib\site-packages\javabridge\jutil.py", line 139, in 
    _find_jvm
    raise JVMNotFoundError()
    javabridge.jutil.JVMNotFoundError: Can't find the Java Virtual Machine
java python weka
1个回答
0
投票

我不是Windows用户,设置Python似乎总是充满问题...但我终于有一些时间设置Windows 10实例......这就是我做的:

  • 没有定义JAVA_HOME变量
  • java可执行文件的位置:
where java
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\ProgramData\Oracle\Java\javapath\java.exe
  • 安装Java版本:
java -version
java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)
C:\Program Files (x86)\Common Files\Oracle\Java\javapath;C:\ProgramData\Oracle\Java\javapath;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\WINDOWS\System32\OpenSSH\;C:\Anaconda2;C:\Anaconda2\Scripts;C:\Anaconda2\Library\bin;C:\Users\fracpete\AppData\Local\Microsoft\WindowsApps;
  • 为pww创建anaconda环境(numpy需要通过anaconda安装):
conda create -n py27-pww numpy
  • 激活环境:
activate py27-pww
  • 安装pww:
pip install python-weka-wrapper
  • 测试pww:
python
import weka.core.jvm as jvm
jvm.start()
from weka.classifiers import Classifeir
cls = Classifier(classname="weka.classifiers.trees.J48")
print(cls)
jvm.stop()
© www.soinside.com 2019 - 2024. All rights reserved.