GAE与Protobuf兼容吗?

时间:2014-05-27 20:17:44

标签: protocol-buffers

文档(https://developers.google.com/appengine/docs/python/datastore/functions)警告GAE不支持协议缓冲区的开源实现(https://code.google.com/p/protobuf)。我找不到任何其他提及支持的内容。

此外,我不清楚哪种实现与GCD(https://developers.google.com/datastore/docs/apis/v1beta2/proto)API兼容。

如果我pip install protobuf,那么我从protoc生成的python代码中得到以下错误:

  

ImportError:没有名为protobuf的模块

我猜这是因为GAE提供的系统路径上有一个不支持protobuf的“google”软件包?有很多黑客/解决方法(例如,https://code.google.com/p/protobuf-gae-hack/)。

protobuf有官方支持吗?是否有人在不同的Google Cloud产品(例如,GAE,GCE,GCD)中可靠地使用PB?

谢谢,

RB

1 个答案:

答案 0 :(得分:3)

可以将开源protobuf库与app引擎一起使用,但您必须合并模块路径,以便系统“google.appengine”'模块可以与google.protobuf'一起访问。例如,如果您使用pip在项目的lib /目录中安装protobuf,则以下代码将lib / google路径与系统提供的google路径合并。

import os
lib = os.path.join(os.path.dirname(__file__), 'lib')
sys.path.insert(0, lib)

import google
google.__path__.append(os.path.join(lib, 'google'))
相关问题