无法通过python脚本和chaquopy在Android中启动stanfordtag的java.exe

2022-04-23 00:00:00 python stanford-nlp android java chaquopy
我想要启动我的python脚本,它使用nltk和Stanford标记器分析文本数据。 问题是我没有启动复制的java.exe的权限。

启动stanfordtag的代码为:

    #set java path in environment variables
    java_path = fct.lib_dir + "java.exe"
    os.environ['JAVAHOME'] = java_path
    #load stanford NER
    sn = StanfordNERTagger(
    fct.lib_dir+"german.distsim.crf.ser.gz", 
    path_to_jar=fct.lib_dir+"stanford-ner.jar")

这是错误:

    com.chaquo.python.PyException: PermissionError: [Errno 13] Permission denied: '/data/user/0/com.pro.useyournotes/files/chaquopy/AssetFinder/app/library_files/java.exe'
        at <python>.subprocess._execute_child(subprocess.py:1702)
        at <python>.subprocess.__init__(subprocess.py:854)
        at <python>.nltk.internals.java(internals.py:132)
        at <python>.nltk.tag.stanford.tag_sents(stanford.py:113)
        at <python>.nltk.tag.stanford.tag(stanford.py:91)
        at <python>.uyn_pre_processing.get_tagged_stanford_corpus(uyn_pre_processing.py:185)
        at <python>.uyn_analysis_workflow.analyse_new_data(uyn_analysis_workflow.py:63)
        at <python>.uyn_main.main(uyn_main.py:268)
        at <python>.chaquopy_java.call(chaquopy_java.pyx:285)
        at <python>.chaquopy_java.Java_com_chaquo_python_PyObject_callAttrThrows(chaquopy_java.pyx:257)
        at com.chaquo.python.PyObject.callAttrThrows(Native Method)
        at com.chaquo.python.PyObject.callAttr(PyObject.java:209)
        at com.pro.useyournotes.MainActivity.getPythonHello(MainActivity.kt:70)
        at com.pro.useyournotes.MainActivity.onCreate(MainActivity.kt:59)
        at android.app.Activity.performCreate(Activity.java:7458)
        at android.app.Activity.performCreate(Activity.java:7448)
        at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1286)
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3409)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3614)
        at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:86)
        at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
        at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2199)
        at android.os.Handler.dispatchMessage(Handler.java:112)
        at android.os.Looper.loop(Looper.java:216)
        at android.app.ActivityThread.main(ActivityThread.java:7625)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:524)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:987)

如何解决此问题?或者有没有其他选项可以访问复制的java.exe (从:C:Program FilesJavajdk-14insava.exe";指向:lib_dir=Join(目录名称(文件),";库文件/";) )在python脚本中打开窗口?

java_path = fct.lib_dir + "java.exe"

解决方案

遗憾的是,您需要做更多工作才能使此方法起作用。你需要提供一个完整的JRE,而不仅仅是java可执行文件,而且它必须是为Android构建的,而不是Windows。我不知道有什么简单的方法可以做到这一点,所以我建议您考虑其他选项,例如:

  • 将JAR添加到app/libs目录并从Java或Kotlim调用它
  • 或只需使用其他标记器。

相关文章