我正在尝试通过带有 kotlin 的 Android 工作室中的 chaquopy 插件启动我的 python 脚本。
这是我通过 Kotlin 启动 python 脚本的方式
private fun getPythonHello(): String {
if (! Python.isStarted()) {
Python.start(AndroidPlatform(this));
}
val python = Python.getInstance()
val pythonFile = python.getModule("edit_package_data_to_application")
return pythonFile.callAttr("main").toString()
}
在调试期间,我已经通过 pip 在 gradle(app) 文件中包含了所有必需的库(nltk、scitkit 等)。包含所有库后出现此错误:“AttributeError: 'zipimporter' object has no attribute 'exec_module'”
有谁知道为什么会出现这个错误?
2020-08-25 16:41:32.538 12129-12129/com.pro.useyournotes E/ExceptionTag: com.chaquo.python.PyException: AttributeError: 'zipimporter' object has no attribute 'exec_module'
com.chaquo.python.PyException: AttributeError: 'zipimporter' object has no attribute 'exec_module'
at <python>.dateparser.utils.strptime.patch_strptime(strptime.py:40)
at <python>.dateparser.utils.strptime.<module>(strptime.py:69)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.dateparser.parser.<module>(parser.py:12)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.dateparser.date_parser.<module>(date_parser.py:11)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.dateparser.date.<module>(date.py:12)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.dateparser.<module>(__init__.py:4)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.functionalities_pre_processing.<module>(functionalities_pre_processing.py:22)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.main_useyournotes_analysis.<module>(main_useyournotes_analysis.py:7)
at <python>.java.chaquopy.import_override(import.pxi:26)
at <python>.edit_package_data_to_application.<module>(edit_package_data_to_application.py:14)
at <python>.importlib._bootstrap._call_with_frames_removed(<frozen importlib._bootstrap>:219)
at <python>.importlib._bootstrap_external.exec_module(<frozen importlib._bootstrap_external>:783)
at <python>.java.android.importer.exec_module(importer.py:477)
at <python>.importlib._bootstrap._load_unlocked(<frozen importlib._bootstrap>:671)
at <python>.importlib._bootstrap._find_and_load_unlocked(<frozen importlib._bootstrap>:975)
at <python>.importlib._bootstrap._find_and_load(<frozen importlib._bootstrap>:991)
at <python>.importlib._bootstrap._gcd_import(<frozen importlib._bootstrap>:1014)
at <python>.importlib.import_module(__init__.py:127)
at <python>.chaquopy_java.Java_com_chaquo_python_Python_getModule(chaquopy_java.pyx:153)
at com.chaquo.python.Python.getModule(Native Method)
at com.pro.useyournotes.MainActivity.getPythonHello(MainActivity.kt:69)
at com.pro.useyournotes.MainActivity.onCreate(MainActivity.kt:59)
at android.app.Activity.performCreate(Activity.java:7136)
at android.app.Activity.performCreate(Activity.java:7127)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1271)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2893)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3048)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
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:1808)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:193)
at android.app.ActivityThread.main(ActivityThread.java:6669)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)