LeeKamentsky / python-javabridge

Python wrapper for the Java Native Interface
Other
116 stars 63 forks source link

OpenJDK 11 - Change in `libjvm.so` default location ? #137

Open jlegrand62 opened 6 years ago

jlegrand62 commented 6 years ago

I failed to install javabridge both by pip and a python install using a clone of this GitHub repo. I am using OpenJDK-11 on Ubuntu18.04 LTS. Here is the error message:

Collecting javabridge
  Using cached https://files.pythonhosted.org/packages/68/87/0b016838c2a33b46b8775a3890150c93507931127cf62e9ccf27ac20db34/javabridge-1.0.17.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-install-Ey9unC/javabridge/setup.py", line 396, in <module>
        ext_modules=ext_modules(),
      File "/tmp/pip-install-Ey9unC/javabridge/setup.py", line 131, in ext_modules
        library_dirs = [os.path.dirname(jvm_so)]
      File "/home/jonathan/miniconda2/envs/tissueanalysis-dev/lib/python2.7/posixpath.py", line 122, in dirname
        i = p.rfind('/') + 1
    AttributeError: 'NoneType' object has no attribute 'rfind'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-Ey9unC/javabridge/

This error message not being too helpful, I started digging and I realized that it is failing to find libjvm.so in the function find_jre_bin_jdk_so() (in locate.py) and it returns None for jvm_so, as highlighted by the previous error message. Modifying the locate.py python script I got the following list of directories in which it is searching for libjvm.so:

/usr/lib/jvm/lib/amd64/client/libjvm.so
/usr/lib/jvm/lib/amd64/server/libjvm.so
/usr/lib/jvm/lib/i386/client/libjvm.so
/usr/lib/jvm/lib/i386/server/libjvm.so
/usr/lib/jvm/jre/lib/amd64/client/libjvm.so
/usr/lib/jvm/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/jre/lib/i386/client/libjvm.so
/usr/lib/jvm/jre/lib/i386/server/libjvm.so
/usr/lib/jvm/lib/amd64/client/libjvm.so
/usr/lib/jvm/lib/amd64/server/libjvm.so
/usr/lib/jvm/lib/i386/client/libjvm.so
/usr/lib/jvm/lib/i386/server/libjvm.so
/usr/lib/jvm/jre/lib/amd64/client/libjvm.so
/usr/lib/jvm/jre/lib/amd64/server/libjvm.so
/usr/lib/jvm/jre/lib/i386/client/libjvm.so
/usr/lib/jvm/jre/lib/i386/server/libjvm.so

However a search on my computer indicate this location: /usr/lib/jvm/java-11-openjdk-amd64/lib/server/libjvm.so. Apparently, they removed the architecture sub-directory in this latest version of OpenJDK. In my case, replacing the line 231 in locate.py (find_javahome() definition):

arches = ('amd64', 'i386') if is_linux else ('',)

by:

arches = ('',)

and changing line 124 in locate.py (find_jre_bin_jdk_so() definition):

jdk_dir = os.path.join(java_dir, "..", "..", "..")

by:

jdk_dir = os.path.join(java_dir, "..", "..")

allowed the install process to succeed!

Hope that helps. Thanks for the work!

LeeKamentsky commented 6 years ago

Thanks, Jon, Definitely worth looking into. I will see if I can find some time to replicate and fix. --Lee

yoda-vid commented 6 years ago

I ran into this issue as well, and thanks for pointing out the fix. I also wanted to find a way to support older Java versions and found that I could add an empty string as another element to arches so that libjvm.so could be found in new or old configurations.