作者:mobiledu2502927333 | 来源:互联网 | 2022-11-21 16:54
如何解决《Pythonprotobuf“来自google.protobuf.pyextimport_message”-“ImportError:DLL加载失败:找不到指定的过程”》经验,求助如何解决?
我正在尝试获取一个简单的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)
我希望可以简单地运行它,并将大量的.pb文件(Google字体)转换为.json文件,以便能够对程序中的字体进行分类。
发生的事情是我遇到了以下错误:
Traceback (most recent call last):
File "[path to pythonfile].py", line 5, in
from protobuf.json_format import MessageToJson
File "C:\Python\Lib\site-packages\google\protobuf\json_format.py", line 63, in
from google.protobuf import descriptor
File "[pathToVenv]\venv\lib\site-packages\google\protobuf\descriptor.py", line 47, in
from google.protobuf.pyext import _message
ImportError: DLL load failed: The specified procedure could not be found.
乍一看-h,我的google.protobuf.pyext包中没有“ _message”,但是我尝试了所有从pip获得的google.protobuf版本。Pip可以很好地安装我拥有的所有其他软件包,因此pip不太可能出现问题。但是,在同一软件包中有一个名为“ cpp_message.py”的文件,因此我不确定从何处去。