GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||
GeezerVison is showing github.com — Don't use `pkg_resources.get_distribution(..).version` · Issue #27 · googleapis/python-api-core
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
This repository was archived by the owner on Feb 23, 2026. It is now read-only.
Don't use |
| session.install("-e", ".") |
Is there some way to use pip?
Not for installation sadly no, our packaging standards don't allow it.
Unfortunately we have to be a bit particular about maintaining the version in one place because it needs to be reported in request headers. We currently maintain a single source of truth by placing the version in setup.py.
We could explore moving to another way of single-sourcing the version if more demand. https://packaging.python.org/guides/single-sourcing-package-version/
I'll keep this issue open as a feature request.
Unfortunately we have to be a bit particular about maintaining the version in one place because it needs to be reported in request headers.
That I understand. I'm sure more packages have this problem, I wonder how others do it.
FWIW, both pkg_resources and directly invoking setup.py install are semi-deprecated and are mostly unsupported.
The replacement for pkg_resources.distribution(...).version is importlib.metadata.version(...) (backported to pre-3.7 Python as importlib_metadata), though I doubt that will solve anyone's problem if the installation metadata is simply not present.
More context about the setup.py install deprecation here, but the short answer is that you should always prefer pip install to setup.py install, even in a package manager. A few people (particularly those involved in Arch linux packaging) have been working on minimal PEP 517 build frontend to build wheels and a minimal wheel installer, so possibly early adoption of those technologies will work better for you, @PureTryOut.
@PureTryOut did you happen to figure a way around this? If not we may be able to move the version out of setup.py as @busunkim96 previously indicated.
Also, this is a workaround another project seems to be using. https://github.com/oppia/oppia/pull/10824/files#diff-b6d8dd401ae816cad17bf9926ce3385dR78
Unfortunately I am not reproducing this issue on macos, in a virtualenv, using setup.py build I am passed getting a distribution version when loading the package.
However, as noted above, there is friction using the libraries in GAE. So it is possible we could improve both use cases with the same fix, likely increasing the ability for the version/pkg to be discovered.
❯ python -m venv venv; source venv/bin/activate
❯ python setup.py build
❯ python
Python 3.8.5 (default, Sep 21 2020, 13:30:58)
[Clang 11.0.3 (clang-1103.0.32.62)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import sys
>>> sys.path.append("{MY WORKING DIRECTORY}/build/lib")
>>> from google import api_core
>>> import pkg_resources
>>> pkg_resources.get_distribution("google-api-core").version
'1.22.2'
Could you print more info from the object returned by get_distribution?
I don’t think it is finding info in $PWD/build/lib, because the build command does not create egg-info or dist-info directory. I suspect your call is picking up a previous install of google-api-core.
For the original problem: a nice way to handle this is to invert the process, so have the version in the code and use a build tool that knows how to find the version number in the source (flit, setuptools can do that for example). Then you don’t need to depend on a packaging lib at runtime.