Google Appengine外部cassandra ImportError:没有名为cassandra.cluster的模块

时间:2017-04-25 20:51:45

标签: python-2.7 google-app-engine cassandra datastax google-app-engine-python

尝试从标准环境appengine(开发环境)使用外部托管的Cassandra服务器。我看到了这个错误:

  "..main.py", line 5, in <module>
    import cassandra.cluster
  "..google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 964, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named cassandra.cluster

main.py

import cassandra

# this works ... prints 3.9.0
print cassandra.__version__

# all these variations fail with import error
import cassandra.cluster               
# from cassandra.cluster import Cluster 
# from cassandra import cluster

# this works
import cassandra.metrics

的app.yaml

runtime: python27
api_version: 1
threadsafe: true

- url: /.*
  script: main.app

appengine_config.py

from google.appengine.ext import vendor
vendor.add('lib')

文件夹结构

app.yaml
appengine_config.py
main.py
lib
  |-cassandra
       |-cluster.py
       |-.....
  |-concurrent
  |-six
  • 所有使用pip install -t lib/ cassandra-driver
  • 安装的模块
  • 导入cassandra.metrics,指示路径似乎正常

任何帮助表示感谢。

1 个答案:

答案 0 :(得分:1)

您在sandbox.py, line 964上遇到的错误表明它是从实现C模块的导入钩子中抛出的。 Avinash Raj已经指出你“无法运行具有c扩展名的模块”,这显然是documented

  

解释器无法使用C代码加载Python模块;它是一个“纯粹的”Python环境。

即使cassandra驱动程序支持no-cython installation

pip install -t lib/ --install-option="--no-cython" cassandra-driver

...走这条道路会让我们遇到Python Standard Library's fcntl module的第二个问题:

Traceback (most recent call last):
  File "/home/mroman/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 240, in Handle
    handler = _config_handle.add_wsgi_middleware(self._LoadHandler())
  File "/home/mroman/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 299, in _LoadHandler
    handler, path, err = LoadObject(self._handler)
  File "/home/mroman/google-cloud-sdk/platform/google_appengine/google/appengine/runtime/wsgi.py", line 85, in LoadObject
    obj = __import__(path[0])
  File "/home/mroman/tmp/cassandra_importError/main.py", line 7, in <module>
    import asyncore
  File "/usr/lib/python2.7/asyncore.py", line 608, in <module>
    import fcntl
  File "/home/mroman/google-cloud-sdk/platform/google_appengine/google/appengine/tools/devappserver2/python/sandbox.py", line 964, in load_module
    raise ImportError('No module named %s' % fullname)
ImportError: No module named fcntl

该模块似乎未列入白名单,因为它对文件描述符执行文件控制和I / O控制,而AppEngine的受限“沙箱”不允许应用程序写入文件系统。

我检查了其他Cassandra驱动程序,如:

由于上述所有原因,我相信您唯一的选择是:

干杯