question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Getting JAVA_HOME KeyError while importing autoclass

See original GitHub issue

Before formatting my computer, jnius used to work perfectly. But after formatting and reinstalling again, from jnius import autoclass doesn’t seem to work anymore. Whenever I type that in Python shell, I get this error message:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.7/dist-packages/jnius/__init__.py", line 13, in <module>
    from .reflect import *
  File "/usr/local/lib/python2.7/dist-packages/jnius/reflect.py", line 14, in <module>
    class Class(with_metaclass(MetaJavaClass, JavaClass)):
  File "/usr/local/lib/python2.7/dist-packages/six.py", line 808, in __new__
    return meta(name, bases, d)
  File "jnius/jnius_export_class.pxi", line 43, in jnius.MetaJavaClass.__new__ (jnius/jnius.c:17159)
  File "jnius/jnius_export_class.pxi", line 65, in jnius.MetaJavaClass.resolve_class (jnius/jnius.c:17555)
  File "jnius/jnius_env.pxi", line 11, in jnius.get_jnienv (jnius/jnius.c:3320)
  File "jnius/jnius_jvm_dlopen.pxi", line 89, in jnius.get_platform_jnienv (jnius/jnius.c:3248)
  File "jnius/jnius_jvm_dlopen.pxi", line 48, in jnius.create_jnienv (jnius/jnius.c:2647)
  File "/usr/lib/python2.7/UserDict.py", line 23, in __getitem__
    raise KeyError(key)
KeyError: 'JAVA_HOME'

My JAVA_HOME is set to /usr/lib/jvm/java-7-openjdk-amd64

Do I need to add something else to PATH? Do I need to set path for Python?

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:2
  • Comments:10

github_iconTop GitHub Comments

11reactions
ghostcommented, Oct 23, 2016

@darleison @brandomr I don’t know whether you managed to find a solution, but that worked for me:

  • Open ~/.bashrc file
  • copy this lineexport JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64 export PATH=$JAVA_HOME/bin:$PATH (path / or java version may differ, make sure to check it before copying)
  • save the file and log out
    Hope that helps:)
5reactions
JuggernautPandacommented, Oct 2, 2018

@JuggernautPanda have you found a way around the problem? I’m getting the same error after the suggestions above.

pl@Petar:~$ echo $JAVA_HOME
/usr/lib/jvm/java-8-openjdk-amd64

Above code suggests the move was successful but didn’t change the error.

Hello Petar.

Yes. I did manage to solve it but with a twist -

I did this and it worked.

import os
try:
     from jnius import autoclass

except KeyError:
     os.environ['JDK_HOME'] = "/usr/lib/jvm/java-1.8.0-openjdk-amd64"
     os.environ['JAVA_HOME'] = "/usr/lib/jvm/java-1.8.0-openjdk-amd64"
     from jnius import autoclass
Read more comments on GitHub >

github_iconTop Results From Across the Web

importing pyjnius in python shell gives KeyError - Stack Overflow
#!/usr/bin/python from jnius import autoclass # do something here. I can run this without getting any error but when I try to write...
Read more >
pyjnius 'JAVA_HOME' error - Google Groups
I am having trouble with pyjnius while trying to execute the following code; import jnius. I am getting the following error;
Read more >
pyjnius KeyError: 'JAVA_HOME' on Pycharm
Hello there,I am trying to compile code with jnius in my pycharm python compiler but I get an error like the following. I...
Read more >
barcodes scanner for kivy - Python Forum
Does anyone know of another bar code scanner for Kivy? I tried using this one but i get a key error when i...
Read more >
kivy@groups.io | Messages
[python-for-android:master] New Comment on Issue #653 App crashes ... New Comment on Issue #209 Getting JAVA_HOME KeyError while importing autoclass By.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found