Python protobuf“来自google.protobuf.pyext import _message”-“ ImportError:DLL加载失败:找不到指定的过程”

Gro*_*247 5 python runtime-error protocol-buffers

我正在尝试获取一个简单的Python脚本,以将protobuf文件转换为json文件(我在工作中所需要的格式)。

我已经看到了一些建议,可以升级或降级google.protobuf,以升级到Python 3.6.1(我在3.6.0)。两种解决方案均无济于事。

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)
Run Code Online (Sandbox Code Playgroud)

我希望可以简单地运行它,并将大量的.pb文件(Google字体)转换为.json文件,以便能够对程序中的字体进行分类。

发生的事情是我遇到了以下错误:

Traceback (most recent call last):
  File "[path to pythonfile].py", line 5, in <module>
    from protobuf.json_format import MessageToJson
  File "C:\Python\Lib\site-packages\google\protobuf\json_format.py", line 63, in <module>
    from google.protobuf import descriptor
  File "[pathToVenv]\venv\lib\site-packages\google\protobuf\descriptor.py", line 47, in <module>
    from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.
Run Code Online (Sandbox Code Playgroud)

乍一看-h,我的google.protobuf.pyext包中没有“ _message”,但是我尝试了所有从pip获得的google.protobuf版本。Pip可以很好地安装我拥有的所有其他软件包,因此pip不太可能出现问题。但是,在同一软件包中有一个名为“ cpp_message.py”的文件,因此我不确定从何处去。

Kee*_*ing 7

解决方案是将您的 protobuf 降级到 3.6.0 而不是 3.6.1


小智 6

当我开始使用 TensorFlow 2 和 Keras 时,我遇到了这个错误。在尝试解决错误将近两个小时后,这种组合起作用了:-python 3.6.8(3.6.0 不起作用)-pip 20.0.2-protobuf 3.8.0(3.6 对我不起作用,可能是因为 TensorFlow 2)

体重,-萨米-