python - 如何在谷歌云上安装 ortools 库

标签 python google-app-engine google-cloud-platform or-tools

我正在使用命令 pip install -t lib/ortools ,库 ortools 安装到 lib/ 文件夹。但是,当我在 Google App Engine 上部署包含该库的 Flask 项目时,出现以下错误:

(/base/alloc/tmpfs/dynamic_runtimes/python27g/931d17f05408b3ef/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py:263)
Traceback (most recent call last):
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/931d17f05408b3ef/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/931d17f05408b3ef/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/931d17f05408b3ef/python27/python27_lib/versions/1/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/base/data/home/apps/b~cidy-1539116366694/20190316t002011.416796594015344313/main.py", line 5, in <module>
    from ortools.constraint_solver import pywrapcp
  File "/base/data/home/apps/b~cidy-1539116366694/20190316t002011.416796594015344313/lib/ortools/constraint_solver/pywrapcp.py", line 17, in <module>
    _pywrapcp = swig_import_helper()
  File "/base/data/home/apps/b~cidy-1539116366694/20190316t002011.416796594015344313/lib/ortools/constraint_solver/pywrapcp.py", line 16, in swig_import_helper
    return importlib.import_module('_pywrapcp')
  File "/base/alloc/tmpfs/dynamic_runtimes/python27g/931d17f05408b3ef/python27/python27_dist/lib/python2.7/importlib/__init__.py", line 37, in import_module
    __import__(name)
ImportError: No module named _pywrapcp

最佳答案

第一代(Python 2.7)标准环境沙箱要求非常严格。在这方面特别相关的是 Pure Python一:

All code for the Python runtime environment must be pure Python, and not include any C extensions or other code that must be compiled.

OR-tools 无法满足此要求,因为它们需要(特定于平台的)编译。来自 their installation page :

Note: you can build OR-Tools suite from source for any supported platform only from that platform. OR-Tools Makefile does not support cross-compiling for any supported platform.

可能仍然可以在 GAE 上使用它们:

  • 在第二代标准环境中(Python 3.7,更宽松的限制)——但我不确定是否支持 pip 驱动的包构建以及是否提供了它所需的所有工具,YMMV
  • 在灵活的环境中,最有可能使用 custom-built runtime它甚至允许您添加非 Python 依赖项 - 构建 ortools 可能需要的额外库和工具。

关于python - 如何在谷歌云上安装 ortools 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55191430/

相关文章:

python - BeautifulSoup XML 仅打印第一行

python - 在 Python 中将纳秒转换为时间戳

java - 专用 MySql 服务器与应用程序引擎配合使用

python - 如何在 SQLAlchemy 中为列插入数据库的默认值?

javascript - Django 模板语言 HTML 过滤器

python - 将 BigQuery 连接到 Python

google-app-engine - 如何在本地数据库上进行 GAE headless 测试?

google-cloud-platform - Google Cloud Load Balancer 是否存在单点故障?我们可以有一个备用副本吗?

google-cloud-platform - 在 GCP 中,通过 Cloudbuild 如何确保仅触发文件中发生更改的那些步骤

c# - 方法 'ImageAnnotatorClient.Create' 没有重载需要 1 个参数