I am trying to get Protobuf to work with Python but Python throws an error when trying to import a compiled .proto file. The error is ModuleNotFoundError: No module named 'google'.
This is on a brand new and clean EC2 instance with Ubuntu Linux. Installation of the protocol compiler is by downloading a pre-built binary from the release page and then following the instructions in the readme file, as described here. The full list of commands is shown below. The compilation appears to work but the import fails. What is going wrong? Thanks in advance.
I use scp to copy my_file.proto from the local machine to the EC2 instance. Then SSH to the instance and:
$ wget https://github.com/protocolbuffers/protobuf/releases/download/v21.5/protoc-21.5-linux-x86_64.zip
$ sudo apt install unzip
$ unzip protoc-21.5-linux-x86_64.zip
$ sudo cp bin/protoc /usr/local/bin/.
$ protoc (to test that protoc works)
$ sudo cp -R include/google/ /usr/local/include/.
$ ls /usr/local/include/google/protobuf (to confirm that the copy worked)
$ export SRC_DIR=/home/ubuntu
$ export DST_DIR=/home/ubuntu
$ protoc -I=$SRC_DIR --python_out=$DST_DIR $SRC_DIR/my_file.proto (works)
$ python3
import my_file_pb2 (fails)
The import fails with "ModuleNotFoundError: No module named 'google'"
$ which python3
returns /usr/bin/python3