我正在使用命令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
答案 0 :(得分:1)
第一代(Python 2.7)标准环境沙箱具有非常严格的要求。在这种情况下,特别相关的是Pure Python一个:
Python运行时环境的所有代码必须是纯Python,并且 不包括任何C扩展名或其他必须编译的代码。
OR-tools
无法满足此要求,因为它们需要编译(特定于平台)。来自their installation page:
注意:您只能从源平台为任何受支持的平台构建OR-Tools套件。或工具Makefile不支持 交叉编译任何受支持的平台。
您可能仍然可以在GAE上使用它们:
ortools
可能需要的额外库和工具。答案 1 :(得分:0)
您是否在macOS或Linux上运行pip?如果基于macOS构建,请参见Using Homebrew Python on macOS?
根据OR-Tools Python的官方网站,我认为ortools取决于平台。
当使用平台依赖性python lib时,最好使用pip install -t lib / ortools。 在Linux环境中。