Python on High Sierra “No Java runtime present, requesting install”

high sierrajavapython

I have python code that works just fine in multiple other places and "used" to work on my mac, but now when I try to run my code as:

python <pythonfile>.py

I get an error which says:
No Java runtime present, requesting install.

I have tried all of the fixes on SO and installed the latest Java JDK. The only thing I haven't done is reboot as I'm right in the middle of a lot of things.

Any ideas?

Java JDK

java version "11.0.2" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.2+7-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.2+7-LTS, mixed mode)

Python

mbp-1056:site-packages$ python --version
Python 2.7.10
mbp-1056:site-packages$ type -p python
/usr/bin/python

Code

import time
import json

from confluent_kafka import Producer
from hl7_to_dict import hl7_str_to_dict

#Set up my producer
p = Producer({'streams.producer.default.stream': '/demos/hl7demo/hl7stream'})

str_msg=''
with open("hl7_records_random.txt") as f:
    for line in f:
        if line!='\n':
            str_msg=str_msg+line
        else:
            #print(str_msg)
            d = hl7_str_to_dict(str_msg)
            print json.dumps(d)
            print ("\n\n")
            json_hl7 = json.dumps(d)

            p.produce('allMessages', json_hl7)
            p.produce('adt_topic', json_hl7)
            # Or - just do a json.dumps(your_json) instead of str_msg
            p.flush()
            str_msg=''
            time.sleep(5)

Best Answer

After much pain and anquish, here is what you have to do:

You can either following the instructions here: Stack Overflow Answer

Or you can follow the instructions here: Oliver Dowling Shoutout

In short, you have to edit /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Info.plist (or your equivalent jdk path, only the version will be different) and change:

<key>JVMCapabilities</key>
<array>
    <string>CommandLine</string>
</array>

To:

<key>JVMCapabilities</key>
<array>
    <string>CommandLine</string>
    <string>JNI</string>
    <string>BundledApp</string>
</array>

Then you have to add this symbolic link:

sudo mkdir -p /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bundle/Libraries


sudo ln -s /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/jre/lib/server/libjvm.dylib /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home/bundle/Libraries/libserver.dylib

Post comment if you have an issues!