Skip to content

cljbridge fails to create Java VM #275

Open

Description

@tjg

This:
cljbridge.init_jvm(start_repl=True)

results in:
RuntimeError: Failed to create Java VM. Return code = -1

My context

  • MacOS 15.7.2, Python 3.9.6
  • tested with Java temurin@17 & temurin@21 (via brew install)

Error

At commandline:

% python3 -m venv .venv           
% source .venv/bin/activate
(.venv) % export PATH=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home/bin:$PATH
(.venv) % export JAVA_HOME=$(/usr/libexec/java_home -v 17)                       
(.venv) % env | egrep 'JAVA|JDK'
JAVA_HOME=/Library/Java/JavaVirtualMachines/temurin-17.jdk/Contents/Home

(.venv) % python3               

At Python REPL:

Python 3.9.6 (default, Oct 17 2025, 17:15:53) 
[Clang 17.0.0 (clang-1700.4.4.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> from clojurebridge import cljbridge
>>> test_var=10
>>> cljbridge.init_jvm(start_repl=True)
WARNING: Implicit use of clojure.main with options is deprecated, use -M -e (require '[clojure.tools.build.api :as b]'[clojure.string :as str])(let [basis (b/create-basis {:aliases (map keyword [])}) jvm-args (str/join " " (:jvm-opts (:resolve-args basis)))] (println jvm-args))
Unrecognized option: 
Failed to create Java virtual machine.

Traceback (most recent call last):
  File "/Users/foo/projects/myproject/mycodebase/.venv/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 707, in _javabridge.JB_VM.create_mac
RuntimeError: Failed to create Java VM. Return code = -1
Failed to create Java VM
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/foo/projects/myproject/mycodebase/.venv/lib/python3.9/site-packages/clojurebridge/cljbridge.py", line 170, in init_jvm
    javabridge.start_vm(run_headless=True,
  File "/Users/foo/projects/myproject/mycodebase/.venv/lib/python3.9/site-packages/javabridge/jutil.py", line 319, in start_vm
    raise RuntimeError("Failed to start Java VM")
RuntimeError: Failed to start Java VM

cljbridge version: 0.0.8

(.venv) % python3 -m pip install cljbridge
Requirement already satisfied: cljbridge in ./.venv/lib/python3.9/site-packages (0.0.8)

Activity

  1. behrica commented on Nov 22, 2025

    @behrica
    Contributor

    which version of cljbridge are you using ?
    Your steps above miss how you install "clojure bridge" into your venv

  2. tjg commented on Nov 22, 2025

    @tjg
    Author

    Ah thanks @behrica for noticing, I used this, which installs 0.0.8:

    python3 -m pip install cljbridge
    Requirement already satisfied: cljbridge in ./.venv/lib/python3.9/site-packages (0.0.8)
    ...

    Verifying that it installs 0.0.8 (which appears to be the latest version on PyPI):

    (.venv) % pip show cljbridge
    Name: cljbridge
    Version: 0.0.8
    Summary: An extension og python-javabridge to start Clojure
    Home-page: https://github.com/behrica/clojurebridge
    Author: Carsten Behring
    Author-email: carsten.behring@gmail.com
    License:
    Location: /Users/foo/projects/myproject/mycodebase/.venv/lib/python3.9/site-packages
    Requires: python-javabridge
    Required-by:

    I'll edit my original issue to include this info

  3. behrica commented on Nov 22, 2025

    @behrica
    Contributor

    I can confirm that it fails when uisng python 3.9.6, as you do.
    Can you please try with Python 3.10.16 ?

  4. tjg commented on Nov 22, 2025

    @tjg
    Author

    Hmm, unfortunately it still doesn't work for me...

    Set Python version:

    % brew install pyenv
    ...
    % pyenv global 3.10.16
    % export PATH="$HOME/.pyenv/shims:$PATH"
    % python --version                
    Python 3.10.16

    Run cljbridge:

    % python3 -m pip show cljbridge
    Name: cljbridge
    Version: 0.0.8
    ...
    Location: /Users/foo/.pyenv/versions/3.10.16/lib/python3.10/site-packages
    
    % python3
    Python 3.10.16 (main, Nov 22 2025, 20:22:55) [Clang 17.0.0 (clang-1700.4.4.1)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> from clojurebridge import cljbridge
    >>> cljbridge.init_jvm(start_repl=True)
    WARNING: Implicit use of clojure.main with options is deprecated, use -M -e (require '[clojure.tools.build.api :as b]'[clojure.string :as str])(let [basis (b/create-basis {:aliases (map keyword [])}) jvm-args (str/join " " (:jvm-opts (:resolve-args basis)))] (println jvm-args))
    Unrecognized option: 
    Failed to create Java virtual machine.
    
    Traceback (most recent call last):
      File "/Users/foo/.pyenv/versions/3.10.16/lib/python3.10/site-packages/javabridge/jutil.py", line 282, in start_thread
        vm.create_mac(args, RQCLS, library_path, libjli_path)
      File "_javabridge.pyx", line 707, in _javabridge.JB_VM.create_mac
    RuntimeError: Failed to create Java VM. Return code = -1
    Failed to create Java VM
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/Users/foo/.pyenv/versions/3.10.16/lib/python3.10/site-packages/clojurebridge/cljbridge.py", line 170, in init_jvm
        javabridge.start_vm(run_headless=True,
      File "/Users/foo/.pyenv/versions/3.10.16/lib/python3.10/site-packages/javabridge/jutil.py", line 319, in start_vm
        raise RuntimeError("Failed to start Java VM")
    RuntimeError: Failed to start Java VM
  5. behrica commented on Nov 23, 2025

    @behrica
    Contributor

    I am not familar with MacOs at all.
    Maybe @cnuernber can have a look.

    I see that lately the tests on MacOS fail:
    https://github.com/clj-python/libpython-clj/actions/runs/12223833394

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions