0

我想启动我的 python 脚本,它使用 nltk 和 stanford tagger 分析文本数据。问题是我无权启动复制的 java.exe。

启动 stanfordtagger 的代码是:

    #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 Files\Java\jdk-14\bin\java.exe”到方向:lib_dir = join(dirname( file ),“library_files /" ) ) python 脚本中的窗口?

java_path = fct.lib_dir + "java.exe"
4

1 回答 1

1

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

  • 将 JAR 添加到您的app/libs目录并从 Java 或 Kotlim 调用它
  • 或者干脆使用不同的标注器。
于 2020-08-28T13:41:21.700 回答