javapythonpyinstallerjpype

JPype1=0.7.0: TypeError: Unable to convert str ro java type class java.lang.String


When using JPype1 to convert python str to java.lang.String, i got an error on some windows machines while other windows machines not.

File "lib\site-packages\jpype_jobject.py", line 86, in __new__
TypeError: Unable to convert str to java type class java.lang.String

I pack up the codes into "exe" using PyInstaller 3.5, then run the exe on several windows machines with same JDK, but get different results.

Compile Environment: windows, python 3.6.5 , JPype1 0.7.0, PyInstaller 3.5,
Running Environment: windows, JDK 1.8

import jpype
from jpype import JClass

jpype.startJVM(jpype.getDefaultJVMPath())
mystr = "i'm a string"
jstr = jpype.JObject(mystr, JClass("java.lang.String"))

I tried to read the source code "https://github.com/jpype-project/jpype.git" but didn't get any.

Can anyone lead me in the right direction here?


Solution

  • Finally i found another error log said that JVM was not started successfully. Because there're two versions of jdk on the machine. Although "java -version" shows 1.8, but %JAVA_HOME% is still 1.7.