Chaquopy Android 导入错误
Chaquopy Android import error
我在尝试为 Android 测试 Chaquopy 时遇到 ImportError: No module named six
。似乎与 this question 有关,但据此应该已修复。我可以在 .zip 存档中看到 six.py
文件,并且我已经在我的 python 发行版中安装了六个。
这里是 java 代码:
protected void onResume() {
super.onResume();
if (! Python.isStarted()) {
Python.start(new AndroidPlatform(activity));//error is here!
myInstance = Python.getInstance();
} else {
myInstance = Python.getInstance();
}
myTextView = (TextView) findViewById(R.id.textView);
myButton = (Button) findViewById(R.id.button);
myButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
//Do stuff here
String tt = myInstance.toString();//placeholder
myTextView.setText(tt);
}
});
}
编辑:
我还添加了相关的 gradle 行并重新安装 python 所以它使用默认路径(之前使用 Anaconda)。
完整错误输出:
FATAL EXCEPTION: main
Process: com.example.quant.quantshot, PID: 1188
java.lang.RuntimeException: Unable to resume activity
{com.example.quant.quantshot/com.example.quant.quantshot.MainActivity}:
com.chaquo.python.PyException: Traceback (most recent call last):
File "chaquopy_java.pyx", line 94, in chaquopy_java.init_module (.c:2359)
File "java\chaquopy.pxd", line 19, in init chaquopy_java (.c:11619)
File "/data/user/0/com.example.quant.quantshot/files/chaquopy/chaquopy.zip/java/__init__.py", line 18, in <module>
from .chaquopy import * # noqa
File "java\import.pxi", line 1, in init java.chaquopy (.c:67298)
ImportError: No module named six
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3430)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3470)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2733)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: com.chaquo.python.PyException: Traceback (most recent call last):
File "chaquopy_java.pyx", line 94, in chaquopy_java.init_module (.c:2359)
File "java\chaquopy.pxd", line 19, in init chaquopy_java (.c:11619)
File "/data/user/0/com.example.quant.quantshot/files/chaquopy/chaquopy.zip/java/__init__.py", line 18, in <module>
from .chaquopy import * # noqa
File "java\import.pxi", line 1, in init java.chaquopy (.c:67298)
ImportError: No module named six
at com.chaquo.python.Python.startNative(Native Method)
at com.chaquo.python.Python.start(Python.java:48)
at com.example.quant.quantshot.MainActivity.onResume(MainActivity.java:31)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1269)
at android.app.Activity.performResume(Activity.java:6786)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3407)
... 10 more
这是由于无意中依赖了应用程序内置的 six
造成的。它已在版本 0.4.5 (https://github.com/chaquo/chaquopy/issues/13) 中修复。
我在尝试为 Android 测试 Chaquopy 时遇到 ImportError: No module named six
。似乎与 this question 有关,但据此应该已修复。我可以在 .zip 存档中看到 six.py
文件,并且我已经在我的 python 发行版中安装了六个。
这里是 java 代码:
protected void onResume() {
super.onResume();
if (! Python.isStarted()) {
Python.start(new AndroidPlatform(activity));//error is here!
myInstance = Python.getInstance();
} else {
myInstance = Python.getInstance();
}
myTextView = (TextView) findViewById(R.id.textView);
myButton = (Button) findViewById(R.id.button);
myButton.setOnClickListener(new Button.OnClickListener() {
public void onClick(View v) {
//Do stuff here
String tt = myInstance.toString();//placeholder
myTextView.setText(tt);
}
});
}
编辑:
我还添加了相关的 gradle 行并重新安装 python 所以它使用默认路径(之前使用 Anaconda)。
完整错误输出:
FATAL EXCEPTION: main
Process: com.example.quant.quantshot, PID: 1188
java.lang.RuntimeException: Unable to resume activity
{com.example.quant.quantshot/com.example.quant.quantshot.MainActivity}:
com.chaquo.python.PyException: Traceback (most recent call last):
File "chaquopy_java.pyx", line 94, in chaquopy_java.init_module (.c:2359)
File "java\chaquopy.pxd", line 19, in init chaquopy_java (.c:11619)
File "/data/user/0/com.example.quant.quantshot/files/chaquopy/chaquopy.zip/java/__init__.py", line 18, in <module>
from .chaquopy import * # noqa
File "java\import.pxi", line 1, in init java.chaquopy (.c:67298)
ImportError: No module named six
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3430)
at android.app.ActivityThread.handleResumeActivity(ActivityThread.java:3470)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2733)
at android.app.ActivityThread.-wrap12(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1478)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6121)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
Caused by: com.chaquo.python.PyException: Traceback (most recent call last):
File "chaquopy_java.pyx", line 94, in chaquopy_java.init_module (.c:2359)
File "java\chaquopy.pxd", line 19, in init chaquopy_java (.c:11619)
File "/data/user/0/com.example.quant.quantshot/files/chaquopy/chaquopy.zip/java/__init__.py", line 18, in <module>
from .chaquopy import * # noqa
File "java\import.pxi", line 1, in init java.chaquopy (.c:67298)
ImportError: No module named six
at com.chaquo.python.Python.startNative(Native Method)
at com.chaquo.python.Python.start(Python.java:48)
at com.example.quant.quantshot.MainActivity.onResume(MainActivity.java:31)
at android.app.Instrumentation.callActivityOnResume(Instrumentation.java:1269)
at android.app.Activity.performResume(Activity.java:6786)
at android.app.ActivityThread.performResumeActivity(ActivityThread.java:3407)
... 10 more
这是由于无意中依赖了应用程序内置的 six
造成的。它已在版本 0.4.5 (https://github.com/chaquo/chaquopy/issues/13) 中修复。