AttributeError: module 'jsonschema' has no attribute 'Draft7Validator'

Viewed 876

Please help. I have no idea how to fix this :(

import altair as alt causes the following


<ipython-input-4-8ce2321ae70f> in <module>()
      1 import pandas as pd
----> 2 import altair as alt

~\altair\__init__.py in <module>()
      2 __version__ = "4.2.0.dev0"
      3 
----> 4 from .vegalite import *
      5 from . import examples
      6 

~\altair\vegalite\__init__.py in <module>()
      1 # flake8: noqa
----> 2 from .v4 import *

~\altair\vegalite\v4\__init__.py in <module>()
      1 # flake8: noqa
----> 2 from .schema import *
      3 from .api import *
      4 
      5 from ...datasets import list_datasets, load_dataset

~\altair\vegalite\v4\schema\__init__.py in <module>()
      1 # flake8: noqa
----> 2 from .core import *
      3 from .channels import *
      4 SCHEMA_VERSION = 'v4.17.0'
      5 SCHEMA_URL = 'https://vega.github.io/schema/vega-lite/v4.17.0.json'

~\altair\vegalite\v4\schema\core.py in <module>()
      2 # tools/generate_schema_wrapper.py. Do not modify directly.
      3 
----> 4 from altair.utils.schemapi import SchemaBase, Undefined, _subclasses
      5 
      6 import pkgutil

~\altair\utils\__init__.py in <module>()
----> 1 from .core import (
      2     infer_vegalite_type,
      3     infer_encoding_types,
      4     sanitize_dataframe,
      5     parse_shorthand,

~\altair\utils\core.py in <module>()
     15 import numpy as np
     16 
---> 17 from .schemapi import SchemaBase, Undefined
     18 
     19 try:

~\altair\utils\schemapi.py in <module>()
    141 
    142 
--> 143 class SchemaBase(object):
    144     """Base class for schema wrappers.
    145 

~\altair\utils\schemapi.py in SchemaBase()
    151     _rootschema = None
    152     _class_is_valid_at_instantiation = True
--> 153     _validator = jsonschema.Draft7Validator
    154 
    155     def __init__(self, *args, **kwds):

AttributeError: module 'jsonschema' has no attribute 'Draft7Validator'```
1 Answers

It looks like your version of jsonschema is too old. Altair requires jsonschema newer than version 3.0 and older than version 4.0 (see the requirements file)

You can fix this by running, e.g.

pip install jsonschema==3.2
Related