在GAE标准环境中安装Numpy(v1.9.0),Pandas和SKlearn(Python 27)

时间:2017-12-15 10:38:04

标签: python numpy google-app-engine

我在本地服务器上使用Webapp2成功运行了我的应用程序。现在我希望在Google App Engine上部署它。我正在调试一些错误,因为库不兼容。

要配置应用,我按照Google guide添加第三方插件,例如添加了lib文件夹和:

# appengine_config.py
from google.appengine.ext import vendor

# Add any libraries install in the "lib" folder.
vendor.add('lib')

lib文件夹中,我使用pip install -t lib -r requirements.txt

安装了我的要求
google-cloud-bigquery
oauth2client==4.1.2
google-api-python-client==1.6.4
pandas-gbq
pandas
scipy
scikit-learn==0.18.2
numpy==1.9.0

部署我的应用时,我看到了:

  

Traceback(最近一次调用最后一次):文件   “/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py”   第240行,在Handle中       handler = _config_handle.add_wsgi_middleware(self._LoadHandler())文件   “/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py”   第299行,在_LoadHandler中       handler,path,err = LoadObject(self._handler)文件“/base/alloc/tmpfs/dynamic_runtimes/python27/54c5883f70296ec8_unzipped/python27_lib/versions/1/google/appengine/runtime/wsgi.py”,   第85行,在LoadObject中       obj = import (路径[0])文件“/base/data/home/apps/s~corded-epigram-579/gr:20171215t102242.406232341485344902/main.py”,   第17行,in       导入pandas为pd文件“/base/data/home/apps/s~corded-epigram-579/gr:20171215t1024242.406232341485344902/lib/pandas/init.py”,   第19行,在       “缺少必需的依赖项{0}”。format(missing_dependencies))ImportError:缺少必需的依赖项['numpy']

它基本上告诉我它找不到numpy,但它在lib文件夹中。

我知道谷歌支持numpy v1.6.1,我可以使用app.yaml文件添加,但我需要至少 1.9.0的pandas包。

还添加了我需要运行代码的 main.py 导入的屏幕截图。

enter image description here

2 个答案:

答案 0 :(得分:3)

App Engine standard environment only supports pure Python libraries, except for the built-in libraries provided by Google. Given that Numpy 1.6.1 doesn't work for you, you will need to consider using the flexible environment or anything platform like Compute Engine.

Depending on your application and its requirements, you might be able to architect your application into multiple App Engine "services". For example, say you needed to do some offline or asynchronous analysis using those libraries, you could run that code in a service that targets the flexible environment and have the rest of your application running in a service in the standard environment. The same project can split be split between environments or even languages by virtue of diving the application into services.

答案 1 :(得分:-2)

add init.py file in your lib directory and then

appengine_config.py:

from google.appengine.ext import vendor
import os
vendor.add(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'lib'))#  vendor.add('lib')

then modify your imports to

from lib.something import something