我正在ImportError: No module named six
尝试测试适用于 Android 的 Chaquopy。似乎与这个问题有关,但据此应该修复。我可以six.py
在 .zip 存档中看到该文件,并且在我的 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