0

I encountered an issue with the proto rules provided by rules_python. I believe adding protos that utilizes py_proto_library will overshadow the "google" module, making relevant PIP dependencies unable to be found.

I created a repo with a simple example to demonstrate this. In this example, as long as I do not include proto dependencies(py_proto_library), my app is able to locate the google.protobuf and google.auth modules correctly. However, as soon as I add the proto dependency, I would encounter this issue:

The app code is simple:

import google
print(google.__file__)
import google.protobuf
print(google.protobuf.__file__)
import google.auth
print(google.auth.__file__)

If I have proto dependency, I get this error:

Traceback (most recent call last):
  File "/home/ubuntu/.cache/bazel/_bazel_ubuntu/7e6ecf527bf713b1567f15e2f26950b5/execroot/__main__/bazel-out/k8-fastbuild/bin/app.runfiles/__main__/app.py", line 5, in <module>
    import google.auth
ModuleNotFoundError: No module named 'google.auth'

If I do not have the proto dependencies, the google module is located in

.../pypi_google_auth/site-packages/google/__init__.py

If I switch to include the proto, the google module is in:

.../com_github_protocolbuffers_protobuf/python/google/__init__.py

How can I continue using proto, but also make google.auth accessible? Thank you!

UPDATE: I was able to narrow down the culprit to this change, and verified with a patch. I still don't understand why this is the cause, will spend some time on it.

Chuan Ye
  • 1
  • 1
  • Can you check this and see ```pip show google.auth```. If the python installed is 2.7 try to update 3.7 and see if it works. – SG_Bazel Jul 25 '23 at 13:11
  • Thanks for your reply. However, installing pip dependencies is not something I wish to do, because I have declared all the external pip deps in the requirements.txt and included them as part of my binary. I can verify that I can pull these packages(i.e. I tried Flask) in and use most of them without having to do ```pip install``` on my host machine. However, I believe something happened to that repo that overrode the "google" module, therefore I only have issues with other pip packages that's also using "google". – Chuan Ye Jul 25 '23 at 15:14

0 Answers0