googleapis / python-api-common-protos

Apache License 2.0
18 stars 22 forks source link

No module named 'google.api' when installing via setuptools #209

Closed javihernandez closed 6 months ago

javihernandez commented 6 months ago

First, I'm not sure whether this bug report belongs here or elsewhere, move it to the appropriate place if needed.

We are having a weird problem than can only be reproduced in AlmaLinux 9, and based on investigations, it's directly related to setuptools and how it deals with dependencies. The original report in our project can be found here and it already includes information about what's going on.

Environment details

Steps to reproduce

  1. Clone https://github.com/AlmaLinux/alma-sbom.git
  2. Create a venv: python3 -m venv env && source env/bin/activate
  3. Build and install alma-sbom: python setup.py install
  4. Run alma-sbom: python --help

Stack trace

(env) [root@alma-sbom-env alma-sbom]# ./alma_sbom.py --help
Traceback (most recent call last):
  File "/root/alma-sbom/./alma_sbom.py", line 13, in <module>
    from immudb_wrapper import ImmudbWrapper
  File "<frozen zipimport>", line 259, in load_module
  File "/root/alma-sbom/env/lib64/python3.9/site-packages/immudb_wrapper-0.1.1-py3.9.egg/immudb_wrapper.py", line 15, in <module>
  File "/root/alma-sbom/env/lib64/python3.9/site-packages/immudb_py-1.4.0-py3.9.egg/immudb/__init__.py", line 13, in <module>
    from immudb.client import ImmudbClient
  File "/root/alma-sbom/env/lib64/python3.9/site-packages/immudb_py-1.4.0-py3.9.egg/immudb/client.py", line 18, in <module>
    from immudb import grpcutils
  File "/root/alma-sbom/env/lib64/python3.9/site-packages/immudb_py-1.4.0-py3.9.egg/immudb/grpcutils.py", line 20, in <module>
    import immudb.grpc.schema_pb2_grpc as schema_pb2_grpc
  File "/root/alma-sbom/env/lib64/python3.9/site-packages/immudb_py-1.4.0-py3.9.egg/immudb/grpc/schema_pb2_grpc.py", line 6, in <module>
    from . import schema_pb2 as schema__pb2
  File "/root/alma-sbom/env/lib64/python3.9/site-packages/immudb_py-1.4.0-py3.9.egg/immudb/grpc/schema_pb2.py", line 16, in <module>
    from google.api import annotations_pb2 as google_dot_api_dot_annotations__pb2
ModuleNotFoundError: No module named 'google.api'

As a temporary solution, and since these deps are being pulled by one 3rd party dep of us (immudb-py), we have added both googleapis-common-protos==1.61.0 and protobuf==3.20.3 as dependencies of our immudb-wrapper and it solved the issue. However, I would like to know whether this is a problem in your side, or in setuptools' side of things.

parthea commented 6 months ago

Hi @javihernandez,

I was able to re-create the issue. I was able to solve it by making some tweaks to the install step and setup.py. See the changes below:

(env) (base) root@faa723da89bd:/alma-sbom# git diff
diff --git a/setup.py b/setup.py
index 825f3ab..3c79a9c 100644
--- a/setup.py
+++ b/setup.py
@@ -22,16 +22,12 @@ setup(
     scripts=['alma_sbom.py'],
     install_requires=[
         'requests>=2.20.0',
-        'dataclasses>=0.8',
         'cyclonedx-python-lib==2.7.1',
         'spdx-tools==0.8',
         'urllib3<2.0',
         'packageurl-python==0.10.3',
         'GitPython==3.1.29',
-        'immudb_wrapper',
-    ],
-    dependency_links=[
-        'git+https://github.com/AlmaLinux/immudb-wrapper.git@0.1.4#egg=immudb_wrapper'
+        'immudb_wrapper @ git+https://github.com/AlmaLinux/immudb-wrapper.git@0.1.1#egg=immudb_wrapper',
     ],
     python_requires=">=3.9",
 )

More detail:

ERROR: Could not find a version that satisfies the requirement immudb_wrapper (from alma-sbom) (from versions: none)
ERROR: No matching distribution found for immudb_wrapper
parthea commented 6 months ago

I'm going to close this issue but please feel free to open a new issue if you have additional questions.

javihernandez commented 6 months ago

Thank you for taking the time to look at this @parthea, and for your advice on it. Yes, using pip solves the issue for sure, and moving over pip to install deps is the way to go, so :+1: . Regarding dataclasses, yes, we already had a PR taking care of it. No more questions on my side, this can be closed for sure, thanks a lot again!