konlpy / konlpy

Python package for Korean natural language processing.
http://konlpy.org
Other
1.41k stars 331 forks source link

TypeError: startJVM() got an unexpected keyword argument 'convertStrings' #329

Closed snoop2head closed 3 years ago

snoop2head commented 4 years ago

Situation

Problem

~/.pyenv/versions/nlpkor2/lib/python3.8/site-packages/konlpy/tag/_okt.py in __init__(self, jvmpath, max_heap_size)
     89     def __init__(self, jvmpath=None, max_heap_size=1024):
     90         if not jpype.isJVMStarted():
---> 91             jvm.init_jvm(jvmpath, max_heap_size)
     92 
     93         oktJavaPackage = jpype.JPackage('kr.lucypark.okt')

~/.pyenv/versions/nlpkor2/lib/python3.8/site-packages/konlpy/jvm.py in init_jvm(jvmpath, max_heap_size)
     62 
     63     if jvmpath:
---> 64         jpype.startJVM(jvmpath, '-Djava.class.path=%s' % classpath,
     65                                 '-Dfile.encoding=UTF8',
     66                                 '-ea', '-Xmx{}m'.format(max_heap_size),

TypeError: startJVM() got an unexpected keyword argument 'convertStrings'
coding-Benny commented 3 years ago

Hello. You can solve this problem by following these steps:

  1. Open jvm.py file. It depends on the user and environment, but you can check the location of jvm.py in the log. In your case, jvm.py is located ~/.pyenv/versions/nlpkor2/lib/python3.8/site-packages/konlpy/jvm.py.

  2. Modify lines 66-67 as follows:

    ~/.pyenv/versions/nlpkor2/lib/python3.8/site-packages/konlpy/jvm.py in init_jvm(jvmpath, max_heap_size)
      62 
      63     if jvmpath:
      64         jpype.startJVM(jvmpath, '-Djava.class.path=%s' % classpath,
      65                                 '-Dfile.encoding=UTF8',
    - 66                                 '-ea', '-Xmx{}m'.format(max_heap_size),
    - 67                                  convertString=True)
    + 66                                 '-ea', '-Xmx{}m'.format(max_heap_size))

    convertStrings (bool) – Option to force Java strings to cast to Python strings. This option is to support legacy code for which conversion of Python strings was the default. This will globally change the behavior of all calls using strings, and a value of True is NOT recommended for newly developed code.

You can see more information about convertString and TypeError from JPype User Guide and API Reference.

snoop2head commented 3 years ago

Seems like the issue has been resolved within a year...! The recent version works fine on my local dev environment. Thanks for the walk through!