使用Scikit-learn和Google应用引擎

8

我正在尝试在Google App Engine上部署一个Python2.7应用程序。它使用了像numpy、flask、pandas和scikit-learn这样的几个模块。虽然我能够安装和使用其他模块,但是将scikit-learn安装在项目的lib文件夹中会出现以下错误:

Traceback (most recent call last): File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle handler = _config_handle.add_wsgi_middleware(self._LoadHandler()) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler handler, path, err = LoadObject(self._handler) File "/base/data/home/runtimes/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject obj = __import__(path[0]) File "/base/data/home/apps/s~category-prediction-1247/v1.391344087004233892/deploynew.py", line 6, in import sklearn File "/base/data/home/apps/s~category-prediction-1247/v1.391344087004233892/lib/sklearn/__init__.py", line 56, in from . import __check_build File "/base/data/home/apps/s~category-prediction-1247/v1.391344087004233892/lib/sklearn/__check_build/__init__.py", line 46, in raise_build_error(e) File "/base/data/home/apps/s~category-prediction-1247/v1.391344087004233892/lib/sklearn/__check_build/__init__.py", line 41, in raise_build_error %s""" % (e, local_dir, ''.join(dir_content).strip(), msg)) ImportError: dynamic module does not define init function (init_check_build) ___________________________________________________________________________ Contents of /base/data/home/apps/s~category-prediction-1247/v1.391344087004233892/lib/sklearn/__check_build: setup.pyc __init__.py _check_build.so setup.py __init__.pyc ___________________________________________________________________________ 似乎scikit-learn没有正确构建。如果您从源代码安装了scikit-learn,请不要忘记在使用它之前构建软件包:在源目录中运行python setup.py installmake。如果您使用了安装程序,请检查它是否适合您的Python版本、操作系统和平台。

有没有办法在Google App Engine上使用scikit-learn?


这个错误出现在应用引擎上。我能够成功地使用“pip install -t lib scikit-learn”命令在我正在部署的代码库的lib文件夹中安装Scikit-learn。 - Rndomcoder
3个回答

3

现在可以在App Engine灵活环境上使用Scikit-learn了。

只需要在requirements.txt文件中指定sklearn依赖即可。

请参考此repo,了解如何在App Engine上提供sklearn模型的代码示例。


我想现在它也可以在新的Appengine标准Python3.7环境中使用,就像flex一样,它没有传统App Engine的沙盒限制。 - snakecharmerb
我还没有测试过它。看到它会很有趣。感谢您指出。 - syltruong

2
看起来sci-kit learn在App Engine的Python 2.x标准环境中不受支持,使用托管VM是此情况下的首选解决方案。请参见此错误的解决方法:链接
还可以参考这个类似的问题以获取另一种替代方法。

0

最新发布的第二代Python 3.7标准环境(实验性)可以运行所有模块。不过目前还处于测试阶段。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接