Omics - Hunter

Python jpype警告convertStrings was not specified when starting the JVM……

今天用Python调用jpype是出现一段很烦人的警告,搜索了下发现网上很多误导信息,总结到此:

报错信息:
lib\site-packages\jpype\_core.py:210: UserWarning:
-------------------------------------------------------------------------------
Deprecated: convertStrings was not specified when starting the JVM. The default
behavior in JPype will be False starting in JPype 0.8. The recommended setting
for new code is convertStrings=False.  The legacy value of True was assumed for
this session. If you are a user of an application that reported this warning,
please file a ticket with the developer.
-------------------------------------------------------------------------------

  """)

网上给的很多信息,要么降版本,要么修改源码。其实这个官方已经给了方案:

只需要设置:

startJVM(……, convertStrings = False)

即可 。

jpype.startJVM(*args, **kwargs)
Starts a Java Virtual Machine. Without options it will start the JVM with the default classpath and jvmpath.

The default classpath is determined by jpype.getClassPath(). The default jvmpath is determined by jpype.getDefaultJVMPath().

Parameters:	
*args (Optional, str[]) – Arguments to give to the JVM. The first argument may be the path the JVM.

Keyword Arguments:
 	
jvmpath (str) – Path to the jvm library file, Typically one of (libjvm.so, jvm.dll, …) Using None will apply the default jvmpath.
classpath (str,[str]) – Set the classpath for the jvm. This will override any classpath supplied in the arguments list. A value of None will give no classpath to JVM.
ignoreUnrecognized (bool) – Option to JVM to ignore invalid JVM arguments. Default is False.
convertStrings (bool) –
Option to JPype 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.

The default value for this option during 0.7 series is True. The option will be False starting in 0.8. A warning will be issued if this option is not specified during the transition period.

Raises:	
OSError – if the JVM cannot be started or is already running.
TypeError – if an invalid keyword argument is supplied or a keyword argument conflicts with the arguments.

告诉我们一个小道理,多看文档,尤其是官方文档!

参考资料:

1.https://jpype.readthedocs.io


作者:陈浩


版权:本文版权归作者所有


免责声明:本文中使用的部分图片来自于网络或者参考资料,如有侵权,请联系博主:chenhao__@__evvail.com(发件请删除下划线)进行删除


转载注意:除非特别声明,本站点内容均为作者原创文章,转载须以链接形式标明本文链接


本文链接:https://evvail.com/2019/12/21/298.html

3 评论

  1. 可以说下具体怎么修改嘛,我修改后报错,找不到use jar估计路径的问题

    • 陈浩

      2021/2/5 在 23:35

      在调用函数时添加convertStrings = False参数,startJVM(……, convertStrings = False)

    • 陈浩

      2021/2/5 在 23:38

      Java环境路径配置
      1)新建一个名为“JAVA_HOME”的环境变量,变量值为Java的安装路径
      2)Path环境变量添加如下信息:%JAVA_HOME%\bin;%JAVA_HOME%\jre\bin
      3)和JAVA_HOME一样,新建一个名为“classpath”的环境变量,变量值为:%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar

回复 取消回复

如果你有什么好的建议或者疑问请给我留言,谢谢!

Captcha Code