Visitar URL original
Failing imports for submodules of the google-api-core packages · Issue #15023 · googleapis/google-cloud-python · GitHub
Skip to content

Failing imports for submodules of the google-api-core packages #15023

Closed

Description

@glaubitz

We haven't recently started to see import issues with packages that use google-api-core in openSUSE Tumbleweed.

For example, the package celery fails to import google.cloud [1]:

[   21s] ==================================== ERRORS ====================================
[   21s] _________________ ERROR collecting t/unit/backends/test_gcs.py _________________
[   21s] ImportError while importing test module '/home/abuild/rpmbuild/BUILD/python-celery-test-5.5.3-build/celery-5.5.3/t/unit/backends/test_gcs.py'.
[   21s] Hint: make sure your test modules/packages have valid Python names.
[   21s] Traceback:
[   21s] /usr/lib64/python3.11/importlib/__init__.py:126: in import_module
[   21s]     return _bootstrap._gcd_import(name[level:], package, level)
[   21s] t/unit/backends/test_gcs.py:5: in <module>
[   21s]     from google.cloud.exceptions import NotFound
[   21s] E   ModuleNotFoundError: No module named 'google.cloud'
[   21s] =============================== warnings summary ===============================

And indeed that does not work on a test system:

glaubitz@suse-laptop:~> python3
Python 3.13.3 (main, Apr 11 2025, 19:56:42) [GCC] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import google.cloud
Traceback (most recent call last):
  File "<python-input-0>", line 1, in <module>
    import google.cloud
ModuleNotFoundError: No module named 'google.cloud'
>>> 
glaubitz@suse-laptop:~> rpm -q python313-google-api-core
python313-google-api-core-2.25.1-0.noarch
glaubitz@suse-laptop:~> ls -ld /usr/lib/python3.13/site-packages/google/cloud
drwxr-xr-x 4 root root 4096 May 14 11:53 /usr/lib/python3.13/site-packages/google/cloud
glaubitz@suse-laptop:~>

It seems that I am missing something here but I'm not sure what.

Any suggestions?

[1] https://build.opensuse.org/package/live_build_log/devel:languages:python/python-celery:test/openSUSE_Tumbleweed/x86_64

Activity

  1. glaubitz commented on Jun 16, 2025

    @glaubitz
    Author

    The problem is that there is a google name space both in /usr/lib64/python3.13/site-packages/google and /usr/lib/python3.13/site-packages/google, so it affects distributions which are not using canonical Python search paths per architecture.

    On Debian and Ubuntu, which both have such canonical architecture-dependent search paths thanks to MultiArch, the problem does not occur.

  2. parthea commented on Jun 16, 2025

    @parthea
    Contributor

    Hi @glaubitz,

    Please could you provide detailed steps to build this image, or reproduce the problem?

    In the build log, I see the following error however the code pkg_resources.declare_namespace('google') in the stack trace was removed from __init__.py in googleapis/python-api-core#561

    [   21s] ../../../../../../usr/lib64/python3.11/site-packages/google/__init__.py:2
    [   21s]   /usr/lib64/python3.11/site-packages/google/__init__.py:2: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
    [   21s]   Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    [   21s]     __import__('pkg_resources').declare_namespace(__name__)
    [   21s] 
    

    Please could you also share the output of pip freeze within the test environment? It's possible that an old version of a dependency is used, which still has code in google/__init__.py.

  3. glaubitz commented on Jun 16, 2025

    @glaubitz
    Author

    Thanks for the quick reply!

    Hi @glaubitz,

    Please could you provide detailed steps to build this image, or reproduce the problem?

    This is on stock openSUSE Tumbleweed. The issue affects 64-bit targets only.

    In the build log, I see the following error however the code pkg_resources.declare_namespace('google') in the stack trace was removed from __init__.py in #561

    [   21s] ../../../../../../usr/lib64/python3.11/site-packages/google/__init__.py:2
    [   21s]   /usr/lib64/python3.11/site-packages/google/__init__.py:2: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
    [   21s]   Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
    [   21s]     __import__('pkg_resources').declare_namespace(__name__)
    [   21s] 
    

    Please could you also share the output of pip freeze within the test environment? It's possible that an old version of a dependency is used, which still has code in google/__init__.py.

    See attached. Did you see my other message which showed how to workaround the issue?

    pip_freeze.txt

  4. parthea commented on Jun 16, 2025

    @parthea
    Contributor

    In the pip_freeze.txt file I don't see google-cloud-core. Please can you try installing that package in the environment using pip install google-cloud-core?

    This import statement is part of google-cloud-core rather than google-api-core.

    [   21s]     from google.cloud.exceptions import NotFound
    [   21s] E   ModuleNotFoundError: No module named 'google.cloud'
    

    google-cloud-core source lives here. google-cloud-core is only used in a few google-cloud- packages as per this search.

  5. glaubitz commented on Jun 16, 2025

    @glaubitz
    Author

    In the pip_freeze.txt file I don't see google-cloud-core. Please can you try installing that package in the environment using pip install google-cloud-core?

    This import statement is part of google-cloud-core rather than google-api-core.

    This not the problem though as I stated above but sure:

    glaubitz@suse-laptop:~> pip freeze|grep google-cloud
    google-cloud-core==2.4.3
    glaubitz@suse-laptop:~> python3
    Python 3.13.3 (main, Apr 11 2025, 19:56:42) [GCC] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import google.cloud
    Traceback (most recent call last):
      File "<python-input-0>", line 1, in <module>
        import google.cloud
    ModuleNotFoundError: No module named 'google.cloud'
    >>> exit
    glaubitz@suse-laptop:~> 
    
    [   21s]     from google.cloud.exceptions import NotFound
    [   21s] E   ModuleNotFoundError: No module named 'google.cloud'
    

    google-cloud-core source lives here. google-cloud-core is only used in a few google-cloud- packages as per this search.

    Yes, I'm aware of this. But that's not the source of the problem. The problem is that the google namespace exists both in the 64-bit and 32-bit site-packages search path.

  6. parthea commented on Jun 16, 2025

    @parthea
    Contributor

    Is it possible to create a python virtual environment? Does that solve the issue?

    Using this docker image, the import from google.cloud.exceptions import NotFound succeeds. Is it possible to create a reproduction with docker?

    FROM opensuse/tumbleweed:latest
    
    ###################### Install python 3.13.3 and pip
    
    RUN zypper -n install python313
    RUN zypper -n install python3-pip
    
    partheniou@partheniou-vm-3:~/testopensuse$ docker run --rm -it --entrypoint /bin/bash testopensuse
    a824233dcd2f:/ # python3.13 -m venv myvenv
    a824233dcd2f:/ # source myvenv/bin/activate
    (myvenv) a824233dcd2f:/ # pip install google-cloud-core
    Collecting google-cloud-core
      Downloading google_cloud_core-2.4.3-py2.py3-none-any.whl.metadata (2.7 kB)
    Collecting google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6 (from google-cloud-core)
      Downloading google_api_core-2.25.1-py3-none-any.whl.metadata (3.0 kB)
    Collecting google-auth<3.0dev,>=1.25.0 (from google-cloud-core)
      Downloading google_auth-2.40.3-py2.py3-none-any.whl.metadata (6.2 kB)
    Collecting googleapis-common-protos<2.0.0,>=1.56.2 (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading googleapis_common_protos-1.70.0-py3-none-any.whl.metadata (9.3 kB)
    Collecting protobuf!=3.20.0,!=3.20.1,!=4.21.0,!=4.21.1,!=4.21.2,!=4.21.3,!=4.21.4,!=4.21.5,<7.0.0,>=3.19.5 (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading protobuf-6.31.1-cp39-abi3-manylinux2014_x86_64.whl.metadata (593 bytes)
    Collecting proto-plus<2.0.0,>=1.22.3 (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading proto_plus-1.26.1-py3-none-any.whl.metadata (2.2 kB)
    Collecting requests<3.0.0,>=2.18.0 (from google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading requests-2.32.4-py3-none-any.whl.metadata (4.9 kB)
    Collecting cachetools<6.0,>=2.0.0 (from google-auth<3.0dev,>=1.25.0->google-cloud-core)
      Downloading cachetools-5.5.2-py3-none-any.whl.metadata (5.4 kB)
    Collecting pyasn1-modules>=0.2.1 (from google-auth<3.0dev,>=1.25.0->google-cloud-core)
      Downloading pyasn1_modules-0.4.2-py3-none-any.whl.metadata (3.5 kB)
    Collecting rsa<5,>=3.1.4 (from google-auth<3.0dev,>=1.25.0->google-cloud-core)
      Downloading rsa-4.9.1-py3-none-any.whl.metadata (5.6 kB)
    Collecting pyasn1<0.7.0,>=0.6.1 (from pyasn1-modules>=0.2.1->google-auth<3.0dev,>=1.25.0->google-cloud-core)
      Downloading pyasn1-0.6.1-py3-none-any.whl.metadata (8.4 kB)
    Collecting charset_normalizer<4,>=2 (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading charset_normalizer-3.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (35 kB)
    Collecting idna<4,>=2.5 (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading idna-3.10-py3-none-any.whl.metadata (10 kB)
    Collecting urllib3<3,>=1.21.1 (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading urllib3-2.4.0-py3-none-any.whl.metadata (6.5 kB)
    Collecting certifi>=2017.4.17 (from requests<3.0.0,>=2.18.0->google-api-core!=2.0.*,!=2.1.*,!=2.2.*,!=2.3.0,<3.0.0dev,>=1.31.6->google-cloud-core)
      Downloading certifi-2025.6.15-py3-none-any.whl.metadata (2.4 kB)
    Downloading google_cloud_core-2.4.3-py2.py3-none-any.whl (29 kB)
    Downloading google_api_core-2.25.1-py3-none-any.whl (160 kB)
    Downloading google_auth-2.40.3-py2.py3-none-any.whl (216 kB)
    Downloading cachetools-5.5.2-py3-none-any.whl (10 kB)
    Downloading googleapis_common_protos-1.70.0-py3-none-any.whl (294 kB)
    Downloading proto_plus-1.26.1-py3-none-any.whl (50 kB)
    Downloading protobuf-6.31.1-cp39-abi3-manylinux2014_x86_64.whl (321 kB)
    Downloading pyasn1_modules-0.4.2-py3-none-any.whl (181 kB)
    Downloading requests-2.32.4-py3-none-any.whl (64 kB)
    Downloading rsa-4.9.1-py3-none-any.whl (34 kB)
    Downloading certifi-2025.6.15-py3-none-any.whl (157 kB)
    Downloading charset_normalizer-3.4.2-cp313-cp313-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (148 kB)
    Downloading idna-3.10-py3-none-any.whl (70 kB)
    Downloading pyasn1-0.6.1-py3-none-any.whl (83 kB)
    Downloading urllib3-2.4.0-py3-none-any.whl (128 kB)
    Installing collected packages: urllib3, pyasn1, protobuf, idna, charset_normalizer, certifi, cachetools, rsa, requests, pyasn1-modules, proto-plus, googleapis-common-protos, google-auth, google-api-core, google-cloud-core
    Successfully installed cachetools-5.5.2 certifi-2025.6.15 charset_normalizer-3.4.2 google-api-core-2.25.1 google-auth-2.40.3 google-cloud-core-2.4.3 googleapis-common-protos-1.70.0 idna-3.10 proto-plus-1.26.1 protobuf-6.31.1 pyasn1-0.6.1 pyasn1-modules-0.4.2 requests-2.32.4 rsa-4.9.1 urllib3-2.4.0
    
    [notice] A new release of pip is available: 25.0.1 -> 25.1.1
    [notice] To update, run: pip install --upgrade pip
    (myvenv) a824233dcd2f:/ # python3
    Python 3.13.3 (main, Apr 11 2025, 19:56:42) [GCC] on linux
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import google.cloud
    >>> from google.cloud.exceptions import NotFound
    >>> exit()
    (myvenv) a824233dcd2f:/ # which python3
    /myvenv/bin/python3
    
  7. added
    needs more infoThis issue needs more information from the customer to proceed.
    on Jun 16, 2025
  8. glaubitz commented on Jun 16, 2025

    @glaubitz
    Author

    A Python environment does unfortunately not address the distribution problem.

    My intention for this bug report was not to get a user problem solved, but to figure out why google.api suddenly no longer can be imported and it seems that the problem in general is that the Python interpreter cannot handle namespaces that exist in two different search paths.

  9. parthea commented on Jun 16, 2025

    @parthea
    Contributor

    google.api was not mentioned in this issue before the last comment. I also don't see google.api in the log file. If the issue is easily reproducible, would you be willing to create a Dockerfile that demonstrates the problem using this as a starting point?

    FROM opensuse/tumbleweed:latest
    
    ###################### Install python 3.13.3 and pip
    
    RUN zypper -n install python313
    RUN zypper -n install python3-pip
    
  10. glaubitz commented on Jun 16, 2025

    @glaubitz
    Author

    google.api was not mentioned in this issue before the last comment. I also don't see google.api in the log file. If the issue is easily reproducible, would you be willing to create a Dockerfile that demonstrates the problem using this as a starting point?

    It doesn't matter what namespace I'm trying to import. It affects all of them. This is neither specific to google.api nor google.cloud.

    As I have mentioned before, the problem is that there is a google namespace in both /usr/lib64/python3.13/site-packages and /usr/lib/python3.13/site-packages and temporarily renaming the latter from google to anything else fixes the import problem.

    The only reason I reported this issue here is that it worked in the past and I don't think the Python interpreter has introduced breaking changes to it's search path mechanism.

  11. parthea commented on Jun 16, 2025

    @parthea
    Contributor

    Is there a specific version older version of google-api-core or google-cloud-core that works? Regrettably, without a minimal reproduction , or a specific version of some package that introduced some change in behavior, it's going to be difficult to move forward on this issue. If possible, it could be helpful to re-run the last build that succeeded, and change one thing at a time until the specific package/version where things started failing can be identified.

  12. ohmayr commented on Jun 20, 2025

    @ohmayr
    Contributor

    @glaubitz

    Bash script to reproduce the error:

    #!/bin/bash
    #
    # This script tests for a Python import regression in openSUSE Tumbleweed
    # by switching to a specific historical snapshot and running a minimal test case.
    #
    
    set -e
    
    echo "INFO: Checking for container engine..."
    if command -v podman &> /dev/null; then
        CONTAINER_ENGINE="podman"
    elif command -v docker &> /dev/null; then
        CONTAINER_ENGINE="docker"
    else
        echo "ERROR: This script requires 'podman' or 'docker'." >&2
        exit 1
    fi
    echo "INFO: Using '$CONTAINER_ENGINE'."
    
    echo "------------------------------------------------------------"
    echo "INFO: Starting openSUSE Tumbleweed container..."
    echo "------------------------------------------------------------"
    
    $CONTAINER_ENGINE run --rm -i registry.opensuse.org/opensuse/tumbleweed:latest /bin/bash << 'EOF'
    set -ex
    
    # === 1. Prepare the environment ===
    zypper ref
    zypper install -y tumbleweed-cli
    
    # === 2. Switch to a specific historical snapshot ===
    /usr/bin/tumbleweed init
    
    #
    # EDIT THIS LINE TO TEST DIFFERENT DATES
    # Find snapshot IDs at: http://download.opensuse.org/history/
    #
    /usr/bin/tumbleweed switch 20250604
    
    # === 3. Install packages from the snapshot ===
    zypper ref --force-download
    zypper install -y python311-google-api-core python311-google-cloud-storage python311-pytest
    
    # === 4. Query the installed package version ===
    echo "----------------------------------------------------------------"
    echo "INFO: Querying installed version..."
    rpm -qi python311-google-api-core
    echo "----------------------------------------------------------------"
    
    # === 5. Run the test case ===
    echo "from google.cloud.exceptions import NotFound" > /tmp/test_gcs_import.py
    
    echo "INFO: Running test. If this PASSES, the snapshot is good. If it FAILS, the bug exists."
    python3.11 -m pytest /tmp/test_gcs_import.py
    
    EOF
    
    echo "------------------------------------------------------------"
    echo "INFO: Script finished."

    Output Error:

    ==================================== ERRORS ====================================
    _____________________ ERROR collecting test_gcs_import.py ______________________
    ImportError while importing test module '/tmp/test_gcs_import.py'.
    Hint: make sure your test modules/packages have valid Python names.
    Traceback:
    usr/lib64/python3.11/importlib/__init__.py:126: in import_module
        return _bootstrap._gcd_import(name[level:], package, level)
    tmp/test_gcs_import.py:1: in <module>
        from google.cloud.exceptions import NotFound
    E   ModuleNotFoundError: No module named 'google.cloud'
    =============================== warnings summary ===============================
    usr/lib64/python3.11/site-packages/google/__init__.py:2
      /usr/lib64/python3.11/site-packages/google/__init__.py:2: DeprecationWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html
        __import__('pkg_resources').declare_namespace(__name__)
    
    usr/lib64/python3.11/site-packages/google/__init__.py:2
      /usr/lib64/python3.11/site-packages/google/__init__.py:2: DeprecationWarning: Deprecated call to `pkg_resources.declare_namespace('google')`.
      Implementing implicit namespace packages (as specified in PEP 420) is preferred to `pkg_resources.declare_namespace`. See https://setuptools.pypa.io/en/latest/references/keywords.html#keyword-namespace-packages
        __import__('pkg_resources').declare_namespace(__name__)
    
    -- Docs: https://docs.pytest.org/en/stable/how-to/capture-warnings.html
    =========================== short test summary info ============================
    ERROR tmp/test_gcs_import.py
    !!!!!!!!!!!!!!!!!!!! Interrupted: 1 error during collection !!!!!!!!!!!!!!!!!!!!
    ========================= 2 warnings, 1 error in 0.27s =========================
    
    

    Steps to reproduce:

    • Run the bash script above which should result in the mentioned error.

    Notes:

    I've verified that the earliest snapshot which introduces this import error is 20250604. Updating the snapshot to 20250602 and re-running the script does not produce this error. Both these snapshots (up until 20250608) have an identical version of google-api-core which is v2.24.2. This means that google-api-core isn't the direct cause of this issue. The problem is likely in the environment in which it is run. It could be a direct dependency or a core system library.

    Search for google-api-core here to verify the versions:
    20250602: http://download.opensuse.org/history/20250602/tumbleweed/repo/oss/noarch/
    20250604: http://download.opensuse.org/history/20250604/tumbleweed/repo/oss/noarch/

    Next steps:

    File a new bug for Tumbleweed here https://bugzilla.opensuse.org/.

    I hope this helps. Let us know if you have any questions.

  13. added
    status: blockedResolving the issue is dependent on other work.
    externalThis issue is blocked on a bug with the actual product.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    priority: p2Moderately-important priority. Fix may not be included in next release.
    and removed
    needs more infoThis issue needs more information from the customer to proceed.
    on Jun 20, 2025
  14. glaubitz commented on Jun 24, 2025

    @glaubitz
    Author

    @glaubitz
    Notes:

    I've verified that the earliest snapshot which introduces this import error is 20250604. Updating the snapshot to 20250602 and re-running the script does not produce this error. Both these snapshots (up until 20250608) have an identical version of google-api-core which is v2.24.2. This means that google-api-core isn't the direct cause of this issue. The problem is likely in the environment in which it is run. It could be a direct dependency or a core system library.

    Search for google-api-core here to verify the versions: 20250602: http://download.opensuse.org/history/20250602/tumbleweed/repo/oss/noarch/ 20250604: http://download.opensuse.org/history/20250604/tumbleweed/repo/oss/noarch/

    Next steps:

    File a new bug for Tumbleweed here https://bugzilla.opensuse.org/.

    I hope this helps. Let us know if you have any questions.

    Thanks a lot, this is very useful. There is already an open openSUSE bug which is currently assigned to the python-google-api-core package, see: https://bugzilla.suse.com/show_bug.cgi?id=1244918

  15. glaubitz commented on Jun 24, 2025

    @glaubitz
    Author

    The problem is python-protobuf. Downgrading to version 5.29.3 fixes the problem.

  16. parthea commented on Jan 12, 2026

    @parthea
    Contributor

    Transferring to google-cloud-python as the code for python-api-core will be migrated there in 1-3 weeks.

  17. parthea commented on Apr 28, 2026

    @parthea
    Contributor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

externalThis issue is blocked on a bug with the actual product.priority: p2Moderately-important priority. Fix may not be included in next release.status: blockedResolving the issue is dependent on other work.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions