Problem using JPype on Mac OS X: I try to start the JVM but I get a DLL not found, but it is there

1k Views Asked by At

My Python code is:

import jpype

jvm_path = "/Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home/lib/jli/libjli.dylib"

jpype.startJVM(
    jvm_path,
    classpath=['~/org.alloytools.alloy.dist.jar'],
)

I get the following error:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/Users/<username>/research-llm/alloy-bridge/src/__main__.py", line 5, in <module>
    jpype.startJVM(
  File "/Users/<username>/research-llm/alloy-bridge/.env/lib/python3.10/site-packages/jpype/_core.py", line 224, in startJVM
    _jpype.startup(jvmpath, tuple(args),
FileNotFoundError: [Errno 2] JVM DLL not found: /Library/Java/JavaVirtualMachines/microsoft-11.jdk/Contents/Home/lib/jli/libjli.dylib

A few useful diagnostics:

java -version
openjdk version "11.0.12" 2021-07-20
OpenJDK Runtime Environment Microsoft-25199 (build 11.0.12+7)
OpenJDK 64-Bit Server VM Microsoft-25199 (build 11.0.12+7, mixed mode)


javac -version
javac 11.0.12

python --version
Python 3.10.4

pip show jpype1
Name: JPype1 Version: 1.4.1 Summary: A Python to Java bridge. Home-page: https://github.com/jpype-project/jpype Author: Steve Menard Author-email: [email protected] License: License :: OSI Approved :: Apache Software License Location: /Users/username/projects/alloy-bridge/.env/lib/python3.10/site-packages Requires: packaging Required-by:

sw_vers
ProductName: macOS ProductVersion: 13.2.1 BuildVersion: 22D68

Given the context, can someone point me in a right direction? I tried a lot myself but couldn't get it working yet.

1

There are 1 best solutions below

0
aled On

It is possible that the issue is due to different architectures. Ensure that your Python and JDK installations use the same architecture. For example for the M1 Apple chip architecture.