You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Package breaks when importlib metadata isn't available (Pyinstaller) #1042
__init__.py calls importlib.metadata.version() at import time :
This breaks when the package metadata isn't bundled (I use PyInstaller and run into this issue) . I can get around this fine by bundling metadata or doing other hacks, but I think just using a try check is the correct approach.
Proposed Solution
Fall back to unknown when the metadata is missing. I saw this pattern being used in the PyVisa repo.
try: version = version(name)
except PackageNotFoundError: version = "unknown"
Collect distribution metadata automatically. This works by scanning collected Python files for uses of:
pkg_resources.get_distribution()
pkg_resources.require()
importlib.metadata.distribution()
importlib.metadata.metadata()
importlib.metadata.files()
importlib.metadata.version()
In all cases, the metadata will only be collected if the distribution name is given as a plain string literal. Anything more complex will still require a hook containing :func:PyInstaller.utils.hooks.copy_metadata. (:issue:#5830)
This wasn't working because we were calling importlib.metadata.version(__name__) rather than importlib.metadata.version("nidaqmx"). Changing it to use a string literal seems to make PyInstaller copy the package metadata.
I also added the try/except, in case there are other scenarios that run into this.
Activity
bkeryan commentedon Nov 4, 2026
@Phillip-Miller Thank you for reporting this. It looks like https://github.com/ni/nitypes-python/blob/main/src/nitypes/__init__.py and https://github.com/ni/nipanel-python/blob/main/src/nipanel/__init__.py will need the same fix.
bkeryan commentedon Nov 11, 2026
https://github.com/pyinstaller/pyinstaller/blob/master/doc/CHANGES.rst#44-2021-07-13
This wasn't working because we were calling
importlib.metadata.version(__name__)rather thanimportlib.metadata.version("nidaqmx"). Changing it to use a string literal seems to make PyInstaller copy the package metadata.I also added the try/except, in case there are other scenarios that run into this.