构建 Python 个包成功,但 Scikit-learn 构建不正确

Building Python packages succeeds, but Scikit-learn is improperly built

我使用 Scikit-learn 和 Kivy 创建了一个应用程序,它是用 Buildozer 构建的。

这是main.py的代码:

# coding=utf-8

import kivy
import sys
kivy.require('1.9.0')

from kivy.app import App
from kivy.uix.label import Label

class MyApp(App):

    def build(self):
        try:
            from sklearn import svm, datasets
        except:
            return Label(text=str(sys.exc_info()[1]))
        else:
            return Label(text='Scikit-learn OK')

if __name__ == '__main__':
    MyApp().run()

我在buildozer.spec的要求中指定了Scikit-learn :

[app]

title = Kivyris

package.name = kivyris

package.domain = org.test

source.dir = .

source.include_exts = py,png,jpg,kv,atlas

version = 0.1

requirements = kivy,numpy,scipy,scikit-learn

orientation = landscape

fullscreen = 1

log_level = 2

warn_on_root = 1

I 运行 buildozer android_new debug deploy run(没有错误,已创建和部署 APK 文件)但在启动应用程序时出现以下错误:

Cannot load library:


Contents of /data/data/org.test.kivyris/files/app/lib/python2.7/site-packages/sklearn/check_build: __init.pyo setup.pyo _check_build.so


It seems that sckikit-learn has not been built correctly.

If you have installed scikit-learn from source, please do not forget to build the package before using it; run python setup.py install or make in the source directory.

If you have used an installer, please check that it is suited for your Python version, your operating system and your platform.

在 Windows 和 Ubuntu 上使用 python main.py 效果很好:

Scikit-Learn OK

我在 Ubuntu 16.04 LTS 上使用 sudo apt-get install python-scikits-learn 安装了 Scikit-learn。这是我 运行 应用所在设备的一些信息:

我试了几次都不成功,所以我上网看了看:

我没有找到任何有用的东西,我也不知道如何解决。有什么想法吗?

谢谢。

当您尝试使用使用纯 Python 的模块为 Android 构建应用程序时,一切正常:此模块将由 Python 运行为 Android 构建并随您的应用一起提供的解释器。

当您尝试为 Android 构建包含 C 扩展的模块或具有 C 扩展的依赖项(例如 Scikit-learn)的应用程序时,情况会更糟。在 Windows 或 Linux C Extensions would be 上使用 distutils 编译,但对于 Android 这是个问题:C Extensions can't be compiled this way.

python-for-android 处理这个问题 providing 食谱机制:

recipe: A recipe is a file that defines how to compile a requirement. Any libraries that have a Python extension must have a recipe in p4a, or compilation will fail. If there is no recipe for a requirement, it will be downloaded using pip.

您可以看到现有食谱列表here。如您所见,没有人为 Scikit-learn 做过一个,所以我认为它现在不能为 Android 构建。

你可以试试create recipe for this module manually or ask someone to help in kivy Google group。请注意,这可能不是一项简单的任务。