google-cloud-python icon indicating copy to clipboard operation
google-cloud-python copied to clipboard

UserWarning: pkg_resources is deprecated as an API

Open tlienart opened this issue 7 months ago • 2 comments

I apologise in advance if this isn't the right repo to post this. I'm using google-cloud-* python libraries with python 3.12 and the UV package manager.

When loading a module like bigquery or storage in an interactive session such as ipython, I get:

In [1]: from google.cloud import storage
/${PATH}/.venv/lib/python3.12/site-packages/google/__init__.py:16:
UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html.
The pkg_resources package is slated for removal as early as 2025-11-30.
Refrain from using this package or pin to Setuptools<81.
  import pkg_resources

In .venv/lib/python3.12/site-packages/google/__init__.py I can see:

try:
    import pkg_resources

    pkg_resources.declare_namespace(__name__)
except ImportError:
    import pkgutil

    __path__ = pkgutil.extend_path(__path__, __name__)

Pinning setuptools in my project to 80 does fix the warning message (so I could just go with this) but it's not ideal. Do you have recommendations to properly handle this warning message or is this something that can be expected to be fixed on the google.cloud side?

thanks

tlienart avatar Jun 04 '25 14:06 tlienart

Thanks for reporting this! We are working to figure out the easiest way for users like you to not encounter these warnings. We'll report back!

vchudnov-g avatar Jun 05 '25 16:06 vchudnov-g

Hi everyone,

I am encountering the same issue, but on gcloud function (second generation):

"2025-09-05 /layers/google.python.pip/pip/lib/python3.10/site-packages/google/init.py:16: UserWarning: pkg_resources is deprecated as an API. See https://setuptools.pypa.io/en/latest/pkg_resources.html. The pkg_resources package is slated for removal as early as 2025-11-30. Refrain from using this package or pin to Setuptools<81."

Basically I tried Setuptools == 80.9.0 in the txt requirements but I still get the same error.

How can we set this up for the cloud functions part? Here are the packages I am using that could cause this:

google-cloud-pubsub google-cloud-core google-cloud-bigquery google-cloud-bigquery-storage google-api-core

I suspect that pinning setup tools in the txt doesn't work because the google package is installing by default setuptools > 81?

Many thanks for your support

magikzigo-star avatar Sep 04 '25 23:09 magikzigo-star