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
import tscompare fails with LookupError when setuptools_scm is installed (wheel has no _version.py) #44
I'm trying to run tscompare, and Claude reports: pip install tscompare followed by import tscompare crashes if setuptools_scm is installed in the same environment. In a clean venv (no setuptools_scm) it imports fine.
Result (tscompare 0.2.1, Python 3.12, setuptools_scm installed)
File ".../tscompare/provenance.py", line 25, in <module>
from . import _version
ImportError: cannot import name '_version' from partially initialized module 'tscompare'
...
File ".../tscompare/provenance.py", line 32, in <module>
__version__ = get_version(root="..", relative_to=__file__)
...
LookupError: setuptools-scm was unable to detect version for .../site-packages.
Cause
The 0.2.1 wheel doesn't contain tscompare/_version.py (contents: __init__.py, methods.py, provenance.py). So in provenance.py, from . import _version raises ImportError, and the fallback runs:
When setuptools_scm is importable, get_version runs against site-packages, which has no git metadata, and raises LookupError. That isn't caught, so the whole package fails to import. Without setuptools_scm, the ImportError is swallowed and __version__ stays "undefined", which hides the problem.
setuptools_scm is commonly present (e.g. in environments with tsdate or tskit installed from source), so this will affect many users.
Suggested fixes
Make sure _version.py is written into the wheel at build time (version_file / write_to in [tool.setuptools_scm]), so the fallback is never reached. This looks like the root cause.
Make the fallback robust: catch LookupError as well as ImportError (or except Exception), or use importlib.metadata.version("tscompare") instead of calling setuptools_scm at runtime.
Workaround: install from a git clone (pip install -e ./tscompare), where setuptools_scm can read the version from git, or uninstall setuptools_scm.
I saw the same error with the 0.2.1 wheel from PyPI and with pip install git+https://github.com/tskit-dev/tscompare.git.
That's good. Well, tell Claude to do whatever msprime is doing to solve this, and in general to review other tskit-dev projects first before suggesting solutions de novo. It's worth adding this to your Claude.md.
Activity
jeromekelleher commentedon Oct 28, 2026
Is this just tscompare or does it happen with other tskit-dev packages like msprime too? It should be a standardised usage across projects.
hyanwong commentedon Oct 29, 2026
There is no error with msprime or tskit:
jeromekelleher commentedon Oct 29, 2026
That's good. Well, tell Claude to do whatever msprime is doing to solve this, and in general to review other tskit-dev projects first before suggesting solutions de novo. It's worth adding this to your Claude.md.
Fix tskit-dev#44
Fix tskit-dev#44
hyanwong commentedon Oct 29, 2026
Fixed in #46
Update provenance to catch setuptools_scm error