tskit-dev / pyslim

Tools for dealing with tree sequences coming to and from SLiM.
MIT License
26 stars 23 forks source link

AttributeError in jsonschema #329

Closed ans6160 closed 9 months ago

ans6160 commented 9 months ago

Hi,

I just installed pyslim to use with msprime and when I import pyslim, I am hit with tracebacks and an attribute error:

>>> import pyslim Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/pyslim/__init__.py", line 4, in <module> from pyslim.slim_metadata import * # NOQA ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/pyslim/slim_metadata.py", line 438, in <module> slim_metadata_schemas = {k: tskit.MetadataSchema(_raw_slim_metadata_schemas[k]) for k in _raw_slim_metadata_schemas} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/pyslim/slim_metadata.py", line 438, in <dictcomp> slim_metadata_schemas = {k: tskit.MetadataSchema(_raw_slim_metadata_schemas[k]) for k in _raw_slim_metadata_schemas} ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/tskit/metadata.py", line 639, in __init__ codec_instance = codec_cls(schema) ^^^^^^^^^^^^^^^^^ File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/tskit/metadata.py", line 580, in __init__ StructCodecSchemaValidator.check_schema(schema) File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/jsonschema/validators.py", line 301, in check_schema for error in validator.iter_errors(schema): File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/jsonschema/validators.py", line 368, in iter_errors for error in errors: File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/tskit/metadata.py", line 196, in binary_format_validator yield from jsonschema._validators.type(validator, types, instance, schema) ^^^^^^^^^^^^^^^^^^^^^^ File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/jsonschema/__init__.py", line 105, in __getattr__ raise AttributeError(f"module {__name__} has no attribute {name}") AttributeError: module jsonschema has no attribute _validators. Did you mean: 'validators'?

pyslim version: 1.0.4 msprime version: 1.2.0

I am not sure how to resolve this issue. Any help would be greatly appreciated!

-Abby

bhaller commented 9 months ago

Hi! There has been discussion of this on the tskit Slack recently. That discussion said:

Not sure in which repo it needs to go as an issue but I think I've stumbled on a version incompatibility with jsonschema. Got this error trying to import pyslim in an environment but it seems the culprit is tskit. This issue seems to be from this change in jsonschema https://github.com/python-jsonschema/jsonschema/blob/main/CHANGELOG.rst#v4190, so reverting to v4.18.6 works.

Here is the tskit issue that was opened:

https://github.com/tskit-dev/tskit/issues/2840

So for now you can resolve this by reverting to an older jsonschema, and you may wish to watch that other issue to see what happens with it. @petrelharp I'll leave this for you to close as you wish.

jiseonmin commented 9 months ago

Hi, I ran into the same issue. Running pip install jsonschema==4.18.6, as suggested above, solved it!

petrelharp commented 9 months ago

Yep, thanks, all! This is an upstream issue with tskit (we can tell because the last packagereferenced before jsonschema is tskit:)

File "/Users/ans6160/anaconda3/envs/msprime/lib/python3.11/site-packages/tskit/metadata.py", line 580, in __init__