属性错误:缺少六个“;“索引字节”;使用自定义python插件编译protobuf时
我在使用自定义python插件编译protobuf文件时遇到了一个问题。在一台机器上,它按预期运行,而在另一台机器上,这会导致以下错误:属性错误:缺少六个“;“索引字节”;使用自定义python插件编译protobuf时,python,python-2.7,protocol-buffers,six,protoc,Python,Python 2.7,Protocol Buffers,Six,Protoc,我在使用自定义python插件编译protobuf文件时遇到了一个问题。在一台机器上,它按预期运行,而在另一台机器上,这会导致以下错误: Traceback (most recent call last): File "C:\...\my_plugin.py", line 14, in <module> from google.protobuf.compiler import plugin_pb2 as plugin File "C:\Pyt
Traceback (most recent call last):
File "C:\...\my_plugin.py", line 14, in <module>
from google.protobuf.compiler import plugin_pb2 as plugin
File "C:\Python27\lib\site-packages\google\protobuf\compiler\plugin_pb2.py", line 255, in <module>
DESCRIPTOR._options = _descriptor._ParseOptions(descriptor_pb2.FileOptions(), _b('\n\034com.google.protobuf.compilerB\014PluginProtosZ\tplugin_go'))
File "C:\Python27\lib\site-packages\google\protobuf\descriptor.py", line 869, in _ParseOptions
message.ParseFromString(string)
File "C:\Python27\lib\site-packages\google\protobuf\message.py", line 185, in ParseFromString
self.MergeFromString(serialized)
File "C:\Python27\lib\site-packages\google\protobuf\internal\python_message.py", line 1062, in MergeFromString
if self._InternalParse(serialized, 0, length) != length:
File "C:\Python27\lib\site-packages\google\protobuf\internal\python_message.py", line 1084, in InternalParse
(tag_bytes, new_pos) = local_ReadTag(buffer, pos)
File "C:\Python27\lib\site-packages\google\protobuf\internal\decoder.py", line 181, in ReadTag
while six.indexbytes(buffer, pos) & 0x80:
AttributeError: 'module' object has no attribute 'indexbytes'
--my_plugin_out: protoc-gen-my_plugin: Plugin failed with status code
回溯(最近一次呼叫最后一次):
文件“C:\…\myu plugin.py”,第14行,在
从google.protobuf.compiler导入插件作为插件
文件“C:\Python27\lib\site packages\google\protobuf\compiler\plugin\u pb2.py”,第255行,在
DESCRIPTOR.\u options=\u DESCRIPTOR.\u ParseOptions(DESCRIPTOR\u pb2.FileOptions(),\u b('\n\034com.google.protobuf.compilerB\014PluginProtosZ\tplugin\u go'))
文件“C:\Python27\lib\site packages\google\protobuf\descriptor.py”,第869行,在_ParseOptions中
message.ParseFromString(字符串)
文件“C:\Python27\lib\site packages\google\protobuf\message.py”,第185行,格式为ParseFromString
self.MergeFromString(序列化)
文件“C:\Python27\lib\site packages\google\protobuf\internal\python\u message.py”,第1062行,位于MergeFromString中
if self.\u InternalParse(序列化,0,长度)!=长度:
InternalParse中的文件“C:\Python27\lib\site packages\google\protobuf\internal\python\u message.py”,第1084行
(标记字节,新位置)=本地读取标记(缓冲区,位置)
ReadTag中第181行的文件“C:\Python27\lib\site packages\google\protobuf\internal\decoder.py”
而6.indexbytes(缓冲区、位置)和0x80:
AttributeError:“模块”对象没有属性“indexbytes”
--my_plugin_out:protoc-gen-my_plugin:plugin失败,状态码为
这两台机器都有相同的Python版本:2.7.12
我还确保他们有相同的Protobuf模块版本(3.2.0)和六个模块版本(1.10.0)
因此,我无法理解为什么“six”模块会错过上面调用堆栈中提到的“decoder.py”中所需的“indexbytes”方法。我无法找到根本原因,但似乎Python模块之间存在一些冲突,因为使用virtualenv修复了我的问题。
请参见我无法找到根本原因,但Python模块之间似乎存在一些冲突,因为使用virtualenv修复了我的问题。 看