How to solve 'Failed to open libjli.dylib. RuntimeError: Failed to start Java VM'

72 views
Skip to first unread message

Yujiang Wang

unread,
Nov 18, 2023, 12:54:51 AM11/18/23
to python-weka-wrapper
Hi, all

I'm integrating the Weka interface into a python project and it comes up with the bug:

Failed to open libjli.dylib.
Traceback (most recent call last):
  File "/Users/wyj/opt/anaconda3/lib/python3.9/site-packages/javabridge/jutil.py", line 282, in start_thread
    vm.create_mac(args, RQCLS, library_path, libjli_path)
  File "_javabridge.pyx", line 709, in _javabridge.JB_VM.create_mac
RuntimeError: Failed to create Java VM. Return code = -1
ERROR:javabridge.jutil:Failed to create Java VM
RuntimeError: Failed to start Java VM

my jdk version is 17.0.9 ,my java file configuration is:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home
export PATH=$JAVA_HOME/bin:$PATH

I have already install the python-weka-wrapper3 and python-javabridge

my python code is:
import javabridge
from weka.classifiers import Classifier
from weka.core import jvm


#sys.path.append("/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/")
#os.environ["JAVA_HOME"] = "/Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/"
#jvm.start()
javabridge.start_vm()
print("Java Version:", javabridge.get_vm().get_version())
javabridge.kill_vm()


I don't know how to fix the problem, please give me some suggestions about it, I'll appreciate it. tqvm.
All the best to you all!

Peter Reutemann

unread,
Nov 18, 2023, 2:54:11 PM11/18/23
to python-we...@googlegroups.com
Unfortunately, I don't have access to a Mac...

I just ran the following script (jvm_test.py) on my Linux box successfully:

import weka.core.jvm as jvm
from weka.core.systeminfo import system_info
jvm.start()
print(system_info())
jvm.stop()

For using Java 17, I used:
export JAVA_HOME=/home/fracpete/programs/jdk/jdk-17.0.2+8

For setting up the virtual environment (I don't use anaconda, just
plain virtualenv/pip):
virtualenv -p /usr/bin/python3 venv.test
./venv.test/bin/pip install python-weka-wrapper3

And then ran the above script like:
./venv.test/bin/python python/weka/jvm_test.py

Here is the output of "pip freeze" of this virtual environment:
configurable-objects==0.0.1
numpy==1.24.4
packaging==23.2
python-javabridge==4.0.3
python-weka-wrapper3==0.2.14
simple-data-flow==0.0.1

Cheers, Peter
--
Peter Reutemann
Dept. of Computer Science
University of Waikato, Hamilton, NZ
Mobile +64 22 190 2375
https://www.cs.waikato.ac.nz/~fracpete/
http://www.data-mining.co.nz/
Reply all
Reply to author
Forward
0 new messages