pkg_resources hard-fails on install_requires for entry point.
See original GitHub issueThis has bitten us a few times now, I think that pkg_resources
is a bit aggressive about install_requires
, so when you attempt to invoke an entry point, the install_requires
list is checked, and if any of the dependencies are missing, the script fails to start.
This problem has come up because we have a system that side-loads pre-built source (a la DPKG and presumably other package managers) where the dependencies are declared by the package manager (so install_requires
is actually mostly ignored at install time). Occasionally we have needed to change the name of the package deployed by the package manager even though the importable path has not changed. If someone has the old package name in their install_requires
and invokes their script via python -m mypkg
, it works fine, but if they are invoking through an entry point, the script fails to run because the dependencies are not installed.
To demonstrate, I have prepared a small repository that demonstrates this behavior.
This is a real problem because it occurs at runtime and there doesn’t seem to be any obvious way to “shim” around it other than by providing a dummy package (with no easy way to notify users that they are relying on this dummy package).
I suggest changing the DistributionNotFound
error into a warning instead.
Issue Analytics
- State:
- Created 5 years ago
- Comments:6 (4 by maintainers)
Top GitHub Comments
I see that this issue has been fixed in #2194 by bypassing pkg_resources in the easy_install scripts and instead relying on importlib.metadata:
All you need to do is make sure you have Setuptools 47.2 or later and Python 3.8 or
importlib_metadata
installed.The docs may well be wrong. There was a recent revamp where a passionate user attempted to describe what behavior they expected, but it may not map to the actual implementation. I suspect the actual implementation is that the indicated console script will only be installed if the relevant extras are requested. Here’s what the old docs said, and that sounds closer to the implementation.
Hmm. Looking at the docs, that’s also consistent with what’s written here. In c657e826e, I’ve corrected the documentation to declare that the behavior is implementation-specific.
In another comment, I’ll address the larger issue.