我正在尝试使用一个简单的Python脚本将protobuf文件转换为json文件(我工作所需的格式)。在
我看到了一些升级到python3.6.1(我是3.6.0)的建议,升级/降级谷歌.protobuf. 两种解决方案都没有帮助。在
def convert_to_json(directory: str):
os.chdir(jsonPath)
for (root, dirs, files) in os.walk(os.getcwd()):
for file_ in files:
if os.path.dirname(file_) != root and file_.endswith(".pb"):
json_file: str = MessageToJson(file_)
file_name = (os.path.dirname(file_).split('\\')[-1]) + ".json"
file_path = os.join(jsonPath, file_name)
with open(file_path, "w") as new_file:
new_file.write(json_file)
我希望我的json文件能够转换成.pb格式。在
结果我得到了以下错误:
^{pr2}$乍一看-嗯,我的邮件里没有谷歌.protobuf.pyext包,但我试过各种版本的谷歌.protobuf全部从pip获得。Pip安装了我所有的其他软件包,所以它不可能是Pip的问题。 但是有一个名为“cpp”的文件_消息.py“在同一个包裹里,所以我不知道该怎么办。在
解决方案是将protobuf降级到3.6.0,而不是3.6.1
相关问题 更多 >
编程相关推荐