importlib.metadata entry points might load wrong module and crash
See original GitHub issue$ sip-build --help
Traceback (most recent call last):
File "/usr/bin/sip-build", line 33, in <module>
sys.exit(load_entry_point('sip==5.4.0', 'console_scripts', 'sip-build')())
File "/usr/bin/sip-build", line 25, in importlib_load_entry_point
return next(matches).load()
StopIteration
I have python-sip
as well as sip5
installed on Arch Linux. In the site-packages directory:
$ ls -1d sip-*
sip-4.19.24.dist-info/
sip-5.4.0-py3.8.egg-info/
The 4.x version installs:
sipconfig.py
sipdistutils.py
sip.pyi
sip.so*
The 5.x version installs:
sipbuild/
They’re co-installable because people might need the legacy version, still.
…
It appears pkg_resources is fully capable of finding the needed distribution given version constraint on sip==5.4.0
:
>>> import pkg_resources
>>> pkg_resources.load_entry_point('sip==5.4.0', 'console_scripts', 'sip-build')
<function main at 0x7f4febf588b0>
>>> pprint(pkg_resources.get_distribution('sip==5.4.0').get_entry_map())
{'console_scripts': {'sip-build': EntryPoint.parse('sip-build = sipbuild.tools.build:main'),
'sip-distinfo': EntryPoint.parse('sip-distinfo = sipbuild.distinfo.main:main'),
'sip-install': EntryPoint.parse('sip-install = sipbuild.tools.install:main'),
'sip-module': EntryPoint.parse('sip-module = sipbuild.module.main:main'),
'sip-sdist': EntryPoint.parse('sip-sdist = sipbuild.tools.sdist:main'),
'sip-wheel': EntryPoint.parse('sip-wheel = sipbuild.tools.wheel:main'),
'sip5': EntryPoint.parse('sip5 = sipbuild.legacy.sip5:main')}}
Not so with importlib.metadata, which AFAICT has no way to specify versions or indeed find multiple versions of one distribution (and is finding the old version to boot):
>>> from importlib.metadata import distribution
>>> distribution('sip').metadata['Version']
'4.19.24'
>>> distribution('sip').entry_points
[]
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (2 by maintainers)
Top Results From Across the Web
Issue when using importlib_metadata inside a standalone ...
I'm using PyInstaller to build standalone Python applications, but I've run into issues with importlib_metadata.
Read more >Using importlib.metadata — Python 3.11.1 documentation
importlib_metadata is a library that provides access to the metadata of an installed Distribution Package, such as its entry points or its top-level...
Read more >History - importlib-metadata 5.0.1.dev25+gb74765d ...
#317: De-duplication of distributions no longer requires loading the full metadata for PathDistribution objects, entry point loading performance by ~10x. v4.2.0 ...
Read more >importlib-metadata 0.7 - PyPI
importlib_metadata is a library to access the metadata for a Python package. It is intended to be ported to Python 3.8.
Read more >Source code for psychopy.plugins
Keys are plugin names and values # are their entry point mappings. ... which define entry points in their metadata which pertain to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
In my case this error occurred when installing the package in editable mode (
pip install -e .
), while when installed normally the entry point worked fine (pip install .
)It turns out where was a directory “<package>.egg-info” in the package’s directory, probably from a previous install. Fix was to remove this directory and run
pip install -e .
again.Thank you this helped me a lot! 🥳