TypeError: Couldn't build proto file into descriptor pool!

2,671 views
Skip to first unread message

Brad Post

unread,
Dec 23, 2022, 6:27:08 PM12/23/22
to grpc.io
Hello,

I am working in Python.

I have a proto file in PACKAGE_A that I am trying to import into PACKAGE_B.  Package_A is installed via pip install, so it live in the site_packages of the venv.

Package_B's proto file includes the import "package_a/package_a.proto" at the top of the file.

When I use protoc to compile Package_B's grpc & pb2 files it all works fine, but when I try running Package_B, I get the following error:

ImportError while loading conftest.py

pacakge_b/src/package_b.py:18: in <module>

    DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(

E   TypeError: Couldn't build proto file into descriptor pool!

E   Invalid proto descriptor for file "package_b.proto":

E     package_a/protos/package_a.proto: Import "package_a/protos/package_a.proto" has not been loaded.

E     package_b.Message.foo: "foo" seems to be defined in "package_a.proto", which is not imported by "package_b.proto".  To use it here, please add the necessary import.


I've read a lot of documentation about relative vs. absolute paths, but seems everything I have tried with generating new files isn't working.  I'm trying to leverage building packages and then importing only what's needed for each other package.

Any suggestions would be welcome, and hope all have a great holiday.

Best,

Brad

Suri Gupta

unread,
Mar 29, 2023, 2:50:29 PM3/29/23
to grpc.io
Anyone able to solve this without changing the package names?

Khaireddine Sarraj

unread,
Aug 24, 2023, 12:58:31 PM8/24/23
to grpc.io
hey i faces the same problem where i wanted to create a package where i can import to every microservice i want and it works, and my solution was to add parent directory mapping into the package __init__.py before the import of all the py files 
like the following: 
import sys
from pathlib import Path
sys.path.append(str(Path(__file__).resolve().parent))
after that been added everything works perfectly fine as intended !! 
Reply all
Reply to author
Forward
0 new messages