This is happening because importlib.metadata.packages_distributions was added in Python 3.10, but the current version check implementation allows this to be called for 3.8 and above:
| # TODO(https://github.com/googleapis/python-api-core/issues/835): Remove once we |
| # no longer support Python 3.7 |
| ifsys.version_info< (3, 8): |
| |
| def_get_pypi_package_name(module_name): # pragma: NO COVER |
| """Determine the PyPI package name for a given module name.""" |
| returnNone |
| |
| else: |
| fromimportlibimportmetadata |
| |
| def_get_pypi_package_name(module_name): |
| """Determine the PyPI package name for a given module name.""" |
| try: |
| # Get the mapping of modules to distributions |
| module_to_distributions=metadata.packages_distributions() |
| |
| # Check if the module is found in the mapping |
| ifmodule_nameinmodule_to_distributions: # pragma: NO COVER |
| # The value is a list of distribution names, take the first one |
| returnmodule_to_distributions[module_name][0] |
| else: |
| returnNone# Module not found in the mapping |
| exceptExceptionase: |
| print(f"An error occurred: {e}") |
| returnNone |
| |
Introduced in this commit: d36e896
In our case, this is a problem purely because the error is printed rather than logged, as we are using applications designed around a communication spec that is particularly sensitive to unexpected stdout writes.
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
If you are still having issues, please be sure to include as much information as possible:
Environment details
- OS type and version: Ubuntu 22.04.5 LTS
- Python version: Python 3.9.21
- pip version: 24.3.1
google-api-core version: 2.28.1
Steps to reproduce
- Import
google.api_core in Python REPL - Observed error printed to stdout
Code example
$ .meltano/extractors/tap-bigquery/venv/bin/pythonPython 3.9.21 (main, Dec 3 2024, 17:50:13) [GCC 11.4.0] on linuxType "help", "copyright", "credits" or "license" for more information.Ctrl click to launch VS Code Native REPL>>> import google.api_coreAn error occurred: module 'importlib.metadata' has no attribute 'packages_distributions'/home/reuben/meltano/bigquery-test/.meltano/extractors/tap-bigquery/venv/lib/python3.9/site-packages/google/api_core/_python_version_support.py:252: FutureWarning: You are using a Python version (3.9.21) past its end of life. Google will update google.api_core with critical bug fixes on a best-effort basis, but not with any other fixes or features. Please upgrade to the latest Python version, or at least Python 3.10, and then update google.api_core. warnings.warn(message, FutureWarning)>>>
Stack trace
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!
This is happening because
importlib.metadata.packages_distributionswas added in Python 3.10, but the current version check implementation allows this to be called for 3.8 and above:python-api-core/google/api_core/_python_version_support.py
Lines 150 to 176 in c97b3a0
Introduced in this commit: d36e896
In our case, this is a problem purely because the error is printed rather than logged, as we are using applications designed around a communication spec that is particularly sensitive to unexpected stdout writes.
Thanks for stopping by to let us know something could be better!
PLEASE READ: If you have a support contract with Google, please create an issue in the support console instead of filing on GitHub. This will ensure a timely response.
Please run down the following list and make sure you've tried the usual "quick fixes":
If you are still having issues, please be sure to include as much information as possible:
Environment details
google-api-coreversion: 2.28.1Steps to reproduce
google.api_corein Python REPLCode example
Stack trace
Making sure to follow these steps will guarantee the quickest resolution possible.
Thanks!