我正在编写一个小的python实用程序,它将由中等非技术用户使用,并且需要与一些protobufs接口。
理想情况下,我希望在本地计算机上使用它的唯一前提条件是:
安装了python
* have an SVN checkout of the repository
* run a simple bash script to build the local proto .py definitions
* run "python myutility"不过,我在导入descriptor_pb2.py时遇到了麻烦。我见过Why do I see "cannot import name descriptor_pb2" error when using Google Protocol Buffers?,但希望避免添加运行proto SDK安装程序的额外前提条件。我已经修改了bash脚本,以便在本地层次结构中生成descriptor_pb2.py,这适用于从其他_pb2.py文件导入的第一级,但看起来descriptor_pb2.py本身试图导入descriptor_pb2找不到它:
$ python myutility.py
Traceback (most recent call last):
File "myutility.py", line 4, in <module>
import protos.myProto_pb2
File "/myPath/protos/myProto_pb2.py", line 8, in <module>
from google.protobuf import descriptor_pb2
File "/myPath/google/protobuf/descriptor_pb2.py", line 8, in <module>
from google.protobuf import descriptor_pb2
ImportError: cannot import name descriptor_pb2我的本地文件夹如下所示:
* myutility.py
* google/
* protobuf/
* descriptor.py
* descriptor_pb2.py
* protos
* myProto_ob2.py另外,我是一名python n00b,所以我可能忽略了一些显而易见的东西。
tia,猎户座
发布于 2011-01-12 05:49:35
在descriptor_pb2.py中注释掉descriptor_pb2.py的导入本身解决了我的问题。感谢tim mcclarren的建议!
发布于 2011-01-11 10:37:19
google/protobuf目录中是否存在文件__ init __.py?
https://stackoverflow.com/questions/4653494
复制相似问题