Install Protocol Buffers (protobuf) on Windows
I’m currently converting a few Google App Engine projects from Python 2.7 to Python 3. This includes a bunch of changes to the the code since Google is moving away from the built in Google App Engine classes. During the first few steps of converting the app you start changing out the dependencies still on Python 2.7. During the first step of the guide Overview of migrating bundled App Engine Services I ran into trouble.
After completing the step with pip installing the required libraries and adding the grpcio library to app.yaml the local dev environment wouldn’t start.
INFO 2020-05-17 17:45:51,872 admin_server.py:150] Starting admin server at: http://localhost:8000
Traceback (most recent call last):
File "C:\Users\krikal\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine_python_runtime.py", line 96, in <module>
_run_file(file, globals())
File "C:\Users\krikal\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine_python_runtime.py", line 90, in run_file
execfile(PATHS.script_file(script_name), globals)
File "C:\Users\krikal\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\runtime.py", line 206, in <module>
main()
File "C:\Users\krikal\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\runtime.py", line 177, in main
sandbox.enable_sandbox(config)
File "C:\Users\krikal\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py", line 317, in enable_sandbox
THIRD_PARTY_C_MODULES.get_importable_module_names(config))
File "C:\Users\krikal\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\appengine\tools\devappserver2\python\runtime\sandbox.py", line 867, in init
dep_lib = import(dep_lib_name)
File "C:\Users\krikal\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\google_appengine\google\protobuf_init.py", line 42, in <module>
protobuf_paths)
ImportError: No module named protobuf
After some digging around I realized that the protobuf-3.11.3.dist-info downloaded by pip didn’t really contain any code. Looking at the Cloud SDK protobuf_init.py i realized it’s looking through all the system paths for the actual code. It looped through all the paths adding \google and then trying to load the protobuf module from there.
After some Googeling about how to run it on windows I tested out the drop-in binary in the path to get it to run. The protoc.exe didn’t seem to be picked up so I downloaded the “all” package and dropped in the python folder into \AppData\Local\Google\Cloud SDK\google-cloud-sdk\bin\google.
Protocal Buffers for Windows can be downloaded from github: https://github.com/protocolbuffers/protobuf/releases