viraja1 / grammar-check

GNU Lesser General Public License v3.0
25 stars 5 forks source link

cant find java #2

Open shubham-dua opened 7 years ago

shubham-dua commented 7 years ago

When running the following code:

import grammar_check
tool = grammar_check.LanguageTool('en-GB')
text = 'This are bad.'
matches = tool.check(text)
len(matches)

error is raised:

Traceback (most recent call last):
  File "C:/Python27/coursera/grammar.py", line 2, in <module>
    tool = grammar_check.LanguageTool('en-GB')
  File "C:\Python27\lib\site-packages\grammar_check\__init__.py", line 190, in __init__
    self._start_server_on_free_port()
  File "C:\Python27\lib\site-packages\grammar_check\__init__.py", line 318, in _start_server_on_free_port
    cls._start_server()
  File "C:\Python27\lib\site-packages\grammar_check\__init__.py", line 330, in _start_server
    server_cmd = get_server_cmd(cls._port)
  File "C:\Python27\lib\site-packages\grammar_check\__init__.py", line 541, in get_server_cmd
    java_path, jar_path = get_jar_info()
  File "C:\Python27\lib\site-packages\grammar_check\__init__.py", line 554, in get_jar_info
    raise JavaError(u"can't find Java")
JavaError: can't find Java

Java is installed already and set as global path variable. I have tried looking into the source code. Here is the function which I am unable to understand regarding java path.

def get_jar_info():
    try:
        java_path, jar_path = cache['jar_info']
    except KeyError:
        java_path = which('java')
        if not java_path:
            raise JavaError("can't find Java")
        dir_name = get_directory()
        jar_path = None
        for jar_name in JAR_NAMES:
            for jar_path in glob.glob(os.path.join(dir_name, jar_name)):
                if os.path.isfile(jar_path):
                    break
            else:
                jar_path = None
            if jar_path:
                break
        else:
            raise PathError("can't find languagetool-standalone in {!r}"
                            .format(dir_name))
        cache['jar_info'] = java_path, jar_path
    return java_path, jar_path

Please have a look into this.

MitaliBhurani commented 6 years ago

I am also having the same problem!! Please help. @viraja1

jxmorris12 commented 4 years ago

Hi! Since this project has been abandoned, I started a new fork over at https://github.com/jxmorris12/language_tool_python.

My version supports new versions of Java and LanguageTool. language-check is stuck on Java 8 and LanguageTool 3.2; latest versions are Java 14 and LanguageTool 4.9!

I'm happy to help you with your issue if you raise it over at my repository! Thanks!