无法通过Python脚本和Chaquopy在Android上启动stanfordtagger的java.exe。

huangapple go评论100阅读模式
英文:

Can't start java.exe for stanfordtagger in android via python script and chaquopy

问题

# 在使用nltk和stanford tagger分析文本数据的Python脚本中启动代码部分,但无法运行复制的java.exe文件。

# 启动stanford tagger的代码:
```python
    # 在环境变量中设置Java路径
    java_path = fct.lib_dir + "java.exe"
    os.environ['JAVAHOME'] = java_path
    # 加载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)

如何解决这个问题?或者在Python脚本中是否有其他选项可以访问复制的java.exe(从:"C:\Program Files\Java\jdk-14\bin\java.exe" 到目录:"lib_dir = join(dirname(file), "library_files/")中的windows版本?

java_path = fct.lib_dir + "java.exe"

<details>
<summary>英文:</summary>

I want to start my python script, which analysis text data with nltk and stanford tagger.
The problem is that i have no permission to start the copied java.exe.


The code for starting the stanfordtagger is :
```python
    #set java path in environment variables
    java_path = fct.lib_dir + &quot;java.exe&quot;
    os.environ[&#39;JAVAHOME&#39;] = java_path
    #load stanford NER
    sn = StanfordNERTagger(
    fct.lib_dir+&quot;german.distsim.crf.ser.gz&quot;, 
    path_to_jar=fct.lib_dir+&quot;stanford-ner.jar&quot;)

This is the error:

    com.chaquo.python.PyException: PermissionError: [Errno 13] Permission denied: &#39;/data/user/0/com.pro.useyournotes/files/chaquopy/AssetFinder/app/library_files/java.exe&#39;
        at &lt;python&gt;.subprocess._execute_child(subprocess.py:1702)
        at &lt;python&gt;.subprocess.__init__(subprocess.py:854)
        at &lt;python&gt;.nltk.internals.java(internals.py:132)
        at &lt;python&gt;.nltk.tag.stanford.tag_sents(stanford.py:113)
        at &lt;python&gt;.nltk.tag.stanford.tag(stanford.py:91)
        at &lt;python&gt;.uyn_pre_processing.get_tagged_stanford_corpus(uyn_pre_processing.py:185)
        at &lt;python&gt;.uyn_analysis_workflow.analyse_new_data(uyn_analysis_workflow.py:63)
        at &lt;python&gt;.uyn_main.main(uyn_main.py:268)
        at &lt;python&gt;.chaquopy_java.call(chaquopy_java.pyx:285)
        at &lt;python&gt;.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)

How can i solve this problem? Or is there any other option to access the copied java.exe
(from: "C:\Program Files\Java\jdk-14\bin\java.exe" to the direction: lib_dir = join(dirname(file), "library_files/")
) windows in the python script?

java_path = fct.lib_dir + &quot;java.exe&quot;

答案1

得分: 2

很不幸,要使这种方法生效,您需要进行更多的工作。您需要提供一个完整的JRE,而不仅仅是java可执行文件,并且它必须为Android构建,而不是Windows。我不知道有任何简单的方法来实现这一点,所以我建议您考虑其他选项,比如:

  • 将JAR添加到您的app/libs目录,并从Java或Kotlin中调用它
  • 或者简单地使用不同的标记器。
英文:

Unfortunately you'd need to do much more in order for this approach to work. You'd need to provide a complete JRE, not just the java executable, and it would have to be built for Android, not Windows. I'm not aware of any easy way to do this, so I recommend you look at other options, such as:

  • Add the JAR to your app/libs directory and call it from Java or Kotlim
  • Or simply use a different tagger.

huangapple
  • 本文由 发表于 2020年8月28日 19:21:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/63632812.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定