codenotary / immudb-py

immudb Python SDK
Apache License 2.0
43 stars 7 forks source link

Module import error occured after installing immudb-py with setup.py #73

Closed KAWAHARA-souta closed 3 months ago

KAWAHARA-souta commented 3 months ago

Reproducer:

setup.py

from setuptools import setup
setup(
  install_requires=[
    'immudb-py',
  ],
)

test.py

from immudb import ImmudbClient

reporoduce log

$ python setup.py install 
(...)
$ python -m pip freeze
appier==1.32.0
cachetools==5.3.3
certifi==2024.2.2
charset-normalizer==3.3.2
dataclasses==0.8
ecdsa==0.18.0
google-api==0.1.12
google-api-core==2.18.0
google-auth==2.29.0
googleapis-common-protos==1.63.0
grpcio==1.62.1
idna==3.6
immudb-py==1.4.0
proto-plus==1.24.0.dev0
protobuf==3.20.3
pyasn1==0.5.1
pyasn1-modules==0.3.0
requests==2.31.0
rsa==4.9
six==1.16.0
UNKNOWN==0.0.0
urllib3==2.2.1

$ python test.py
Traceback (most recent call last):
  File "/home/khwarizmi/test/immudb-py/test.py", line 1, in <module>
    from immudb import ImmudbClient
  File "/home/khwarizmi/test/immudb-py/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 "/home/khwarizmi/test/immudb-py/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 "/home/khwarizmi/test/immudb-py/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 "/home/khwarizmi/test/immudb-py/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 "/home/khwarizmi/test/immudb-py/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'

Note:

If I installed immudb-py using pip install, then this error not occured.

Detail of this issue:

It seems that this issue is caused by the combination of versions of googleapis-common-protos and protobuf. googleapis-common-protos==1.62 (released 2023/12/08) has this patch: https://github.com/googleapis/python-api-common-protos/commit/713e3887a3293aea314060e84bdcf8a12eda3d6c I guess, way to make namespace in library changed in this patch. (reference: https://packaging.python.org/en/latest/guides/packaging-namespace-packages/) It seems that there is an issue where namespaces cannot be properly created when installing a combination of googleapis-common-protos 1.62 or later and older protobuf with setuptools.

simple test 1:

test.py:

from google.api import distribution_pb2
print("error doesn't occured.")

setup.py:

from setuptools import setup
setup(
  install_requires=[
    'googleapis-common-protos',
    ''protobuf>=3.13.0,<4.0.0'     # same as immudb-py
  ],
)

log:

$ python setup.py install
(...)
$ python -m pip freeze
googleapis-common-protos==1.63.0
protobuf==3.20.3
UNKNOWN==0.0.0
$ python test.py
Traceback (most recent call last):
  File "/home/khwarizmi/test/immudb-py/test.py", line 1, in <module>
    from google.api import distribution_pb2
ModuleNotFoundError: No module named 'google.api'

simple test 2

setup.py:

from setuptools import setup
setup(
  install_requires=[
    'googleapis-common-protos',
  ],
)

log:

$ python setup.py install
(...)
$ python -m pip freeze
googleapis-common-protos==1.63.0
protobuf==4.25.3
UNKNOWN==0.0.0

$ python test.py
error doesn't occured.

What I want you to do:

My tool using immudb-py is expected to be installed with setuptools. So, I encounterd this issue. immudb-py has the following dependency on protobuf: https://github.com/codenotary/immudb-py/blob/master/setup.py#L34 Is this dependency mandatory? If it is not mandatory, then removing it should solve this issue. Please consider making this change.

SimoneLazzaris commented 3 months ago

I've reproduced the problem. Unfortunately, we do need protobuf: immudb talks protocol buffers, so we need to use that.

Probably we need to upgrade our dependencies.

SimoneLazzaris commented 3 months ago

@KAWAHARA-souta I've update the dependencies (see version 1.4.1), but the problem is still there. Note that using python setup.py install is deprecated.

If you use pip install . instead (the recommended alternative) it will work.

See https://setuptools.pypa.io/en/latest/deprecated/commands.html