I'm trying to get a simple Python script up to convert protobuf files into json files (required format for what I'm doing at work).
I've seen some recommendations to upgrade to Python 3.6.1 (I'm at 3.6.0), up/downgrade google.protobuf. Neither solution helped.
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)
I expected to have this simply run and convert the slew of .pb files (Google Fonts) to .json files to be able to categorize the fonts within my program.
What happened was that I got the following error:
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.
At first glance - duh, I don't have "_message" in my google.protobuf.pyext package, but I've tried various version of google.protobuf all acquired from pip. Pip did just fine installing every other package I have, so it's not likely an issue with pip. There is however a file called, "cpp_message.py" in that same package, so I'm not sure where to go from here.
the solution is to downgrade your protobuf to 3.6.0 instead of 3.6.1
I struggled with this error when I started to play with TensorFlow 2 and Keras. After almost two hours trying to solve the error, this combination worked: - python 3.6.8 (3.6.0 didn't work) - pip 20.0.2 - protobuf 3.8.0 (3.6 didn't worked for me, maybe because TensorFlow 2)
bw, -Sami-
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With