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

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'```

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

AttributeError: module 'numpy.core.multiarray' has no attribute 'from_dlpack'

I'm getting this numpy.core.multiarray attribute error while importing libraries that rely on numpy.
This might be related to importing different versions of NumPy at the same time probably. The deepface, cv2 uses numpy arrays internally so as other libraries. These np versions may be conflicting with each other. How to resolve this?
My imports are:
import pandas as pd
import numpy as np
from deepface import (
DeepFace,
detectors as DeepFace_detectors
)
import cv2
from cv2 import (
CascadeClassifier,
)
from mtcnn.mtcnn import MTCNN
from matplotlib import pyplot
plt.rcParams["axes.grid"] = False
from matplotlib.pyplot import (
imread,
imshow
)
from matplotlib.patches import (
Rectangle,
Circle
)
import glob
import os
import time
AttributeError Traceback (most recent call last)
c:\Users\Documents\scripts\Predictive Analytics\Work\deepface\deepface.ipynb Cell 1 in <cell line: 1>()
----> 1 import pandas as pd
2 import numpy as np
4 from deepface import (
5 DeepFace,
6 detectors as DeepFace_detectors
7 )
File c:\Users\anaconda3\envs\vision\lib\site-packages\pandas\__init__.py:11, in <module>
9 for dependency in hard_dependencies:
10 try:
---> 11 __import__(dependency)
12 except ImportError as e:
13 missing_dependencies.append(f"{dependency}: {e}")
File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\__init__.py:140, in <module>
137 # Allow distributors to run custom init code
138 from . import _distributor_init
--> 140 from . import core
141 from .core import *
142 from . import compat
File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\core\__init__.py:99, in <module>
95 from .numeric import absolute as abs
97 # do this after everything else, to minimize the chance of this misleadingly
98 # appearing in an import-time traceback
---> 99 from . import _add_newdocs
100 from . import _add_newdocs_scalars
101 # add these for module-freeze analysis (like PyInstaller)
File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\core\_add_newdocs.py:1598, in <module>
1447 add_newdoc('numpy.core.multiarray', 'fromfile',
1448 """
1449 fromfile(file, dtype=float, count=-1, sep='', offset=0, *, like=None)
(...)
1539 array_function_like_doc,
1540 ))
1542 add_newdoc('numpy.core.multiarray', 'frombuffer',
1543 """
1544 frombuffer(buffer, dtype=float, count=-1, offset=0, *, like=None)
(...)
1595 array_function_like_doc,
1596 ))
-> 1598 add_newdoc('numpy.core.multiarray', 'from_dlpack',
1599 """
1600 from_dlpack(x, /)
1601
1602 Create a NumPy array from an object implementing the ``__dlpack__``
1603 protocol. Generally, the returned NumPy array is a read-only view
1604 of the input object. See [1]_ and [2]_ for more details.
1605
1606 Parameters
1607 ----------
1608 x : object
1609 A Python object that implements the ``__dlpack__`` and
1610 ``__dlpack_device__`` methods.
1611
1612 Returns
1613 -------
1614 out : ndarray
1615
1616 References
1617 ----------
1618 .. [1] Array API documentation,
1619 https://data-apis.org/array-api/latest/design_topics/data_interchange.html#syntax-for-data-interchange-with-dlpack
1620
1621 .. [2] Python specification for DLPack,
1622 https://dmlc.github.io/dlpack/latest/python_spec.html
1623
1624 Examples
1625 --------
1626 >>> import torch
1627 >>> x = torch.arange(10)
1628 >>> # create a view of the torch tensor "x" in NumPy
1629 >>> y = np.from_dlpack(x)
1630 """)
1632 add_newdoc('numpy.core', 'fastCopyAndTranspose',
1633 """_fastCopyAndTranspose(a)""")
1635 add_newdoc('numpy.core.multiarray', 'correlate',
1636 """cross_correlate(a,v, mode=0)""")
File c:\Users\anaconda3\envs\vision\lib\site-packages\numpy\core\function_base.py:521, in add_newdoc(place, obj, doc, warn_on_python)
475 def add_newdoc(place, obj, doc, warn_on_python=True):
476 """
477 Add documentation to an existing object, typically one defined in C
478
(...)
519 If possible it should be avoided.
520 """
--> 521 new = getattr(__import__(place, globals(), {}, [obj]), obj)
522 if isinstance(doc, str):
523 _add_docstring(new, doc.strip(), warn_on_python)
AttributeError: module 'numpy.core.multiarray' has no attribute 'from_dlpack'
I re-built the conda env which resolved the issue.

Cannot import Kmeans anymore

I tried to import Kmeans
from sklearn.cluster import KMeans
And I got this error :
AttributeError: module 'sklearn.utils._openmp_helpers' has no attribute '__pyx_capi__'
Never had this problem before and that's not the first time I use Kmeans.
I tried to uninstall sklearn and install it again, but that doesn't change anything.
I have the last version of sklearn, if it could help :
import sklearn
sklearn.__version__
'0.24.1'
EDIT : Here's the full error, if you want details :
----> 1 from sklearn.cluster import KMeans
~\Anaconda3\lib\site-packages\sklearn\cluster\__init__.py in <module>
4 """
5
----> 6 from ._spectral import spectral_clustering, SpectralClustering
7 from ._mean_shift import mean_shift, MeanShift, estimate_bandwidth, get_bin_seeds
8 from ._affinity_propagation import affinity_propagation, AffinityPropagation
~\Anaconda3\lib\site-packages\sklearn\cluster\_spectral.py in <module>
17 from ..base import BaseEstimator, ClusterMixin
18 from ..utils import check_random_state, as_float_array, check_scalar
---> 19 from ..metrics.pairwise import pairwise_kernels
20 from ..neighbors import kneighbors_graph, NearestNeighbors
21 from ..manifold import spectral_embedding
~\Anaconda3\lib\site-packages\sklearn\metrics\__init__.py in <module>
39 from ._dist_metrics import DistanceMetric
40
---> 41 from . import cluster
42 from .cluster import adjusted_mutual_info_score
43 from .cluster import adjusted_rand_score
~\Anaconda3\lib\site-packages\sklearn\metrics\cluster\__init__.py in <module>
20 from ._supervised import fowlkes_mallows_score
21 from ._supervised import entropy
---> 22 from ._unsupervised import silhouette_samples
23 from ._unsupervised import silhouette_score
24 from ._unsupervised import calinski_harabasz_score
~\Anaconda3\lib\site-packages\sklearn\metrics\cluster\_unsupervised.py in <module>
14 from ...utils import check_X_y
15 from ...utils import _safe_indexing
---> 16 from ..pairwise import pairwise_distances_chunked
17 from ..pairwise import pairwise_distances
18 from ...preprocessing import LabelEncoder
~\Anaconda3\lib\site-packages\sklearn\metrics\pairwise.py in <module>
31 from ..utils.fixes import sp_version, parse_version
32
---> 33 from ._pairwise_distances_reduction import PairwiseDistancesArgKmin
34 from ._pairwise_fast import _chi2_kernel_fast, _sparse_manhattan
35 from ..exceptions import DataConversionWarning
sklearn\metrics\_pairwise_distances_reduction.pyx in init sklearn.metrics._pairwise_distances_reduction()
AttributeError: module 'sklearn.utils._openmp_helpers' has no attribute '__pyx_capi__'

Which Tensorflow Package for Keras 2.3

I am trying to use Keras on my machine but I keep getting the error message
"AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'".
Stack Trace is:
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
<ipython-input-1-dd13cebc6f04> in <module>
----> 1 import acgan
~/Documents/GitHub/Keras-GAN/acgan/acgan.py in <module>
1 from __future__ import print_function, division
2
----> 3 from keras.datasets import mnist
4 from keras.layers import Input, Dense, Reshape, Flatten, Dropout, multiply
5 from keras.layers import BatchNormalization, Activation, Embedding, ZeroPadding2D
/anaconda3/lib/python3.6/site-packages/keras/__init__.py in <module>
1 from __future__ import absolute_import
2
----> 3 from . import utils
4 from . import activations
5 from . import applications
/anaconda3/lib/python3.6/site-packages/keras/utils/__init__.py in <module>
4 from . import data_utils
5 from . import io_utils
----> 6 from . import conv_utils
7 from . import losses_utils
8 from . import metrics_utils
/anaconda3/lib/python3.6/site-packages/keras/utils/conv_utils.py in <module>
7 from six.moves import range
8 import numpy as np
----> 9 from .. import backend as K
10
11
/anaconda3/lib/python3.6/site-packages/keras/backend/__init__.py in <module>
----> 1 from .load_backend import epsilon
2 from .load_backend import set_epsilon
3 from .load_backend import floatx
4 from .load_backend import set_floatx
5 from .load_backend import cast_to_floatx
/anaconda3/lib/python3.6/site-packages/keras/backend/load_backend.py in <module>
88 elif _BACKEND == 'tensorflow':
89 sys.stderr.write('Using TensorFlow backend.\n')
---> 90 from .tensorflow_backend import *
91 else:
92 # Try and load external backend.
/anaconda3/lib/python3.6/site-packages/keras/backend/tensorflow_backend.py in <module>
52
53 # Private TF Keras utils
---> 54 get_graph = tf_keras_backend.get_graph
55 # learning_phase_scope = tf_keras_backend.learning_phase_scope #
TODO
56 name_scope = tf.name_scope
AttributeError: module 'tensorflow.python.keras.backend' has no attribute 'get_graph'
I googled the issue and found this
https://forums.xilinx.com/t5/Deephi-DNNDK/Module-tensorflow-python-keras-backend-has-no-attribute-get/td-p/1022555
which tells me that it is tensorflow version related, but not which version to use. I am using Python3 on MacOS.
Thank you for your help.
I couldn't reproduce the error you observe with Keras 2.3.0 & tensorflow 2.0.0rc1. Although, I was able to start the training of acgan, I got a different error after one iteration: Resource localhost/_AnonymousVar84/N10tensorflow3VarE does not exist.
I could successfully run the example with the following versions:
Keras 2.2.4/tensorflow 1.14.0
tensorflow 2.0.0rc1 and replace keras with tensorflow.keras in the imports.

How to fix this error while using statsmodels" ImportError: cannot import name 'factorial'"?

I have already gone through this answer
While importing auto_arima from pmdarima: ERROR : cannot import name 'factorial' from 'scipy.misc'
but couldn't fix the error,I do not understand how to use developer version.
Is there any other method for applying Seasonal ARIMA model?
import statsmodels.api as sm
mod = sm.tsa.statespace.SARIMAX(train_weekly.Price,
order=(1, 0, 0),
seasonal_order=(1, 1, 0, 12),
enforce_stationarity=False,
enforce_invertibility=False)
results = mod.fit()
print(results.summary().tables[0])
print(results.summary().tables[1])
Following is the output
ImportError Traceback (most recent call last)
<ipython-input-30-a5d9120bdc57> in <module>()
----> 1 import statsmodels.api as sm
2 mod = sm.tsa.statespace.SARIMAX(train_weekly.Price,
3 order=(1, 0, 0),
4 seasonal_order=(1, 1, 0, 12),
5 enforce_stationarity=False,
3 frames
/usr/local/lib/python3.6/dist-packages/statsmodels/api.py in <module>()
14 from . import robust
15 from .robust.robust_linear_model import RLM
---> 16 from .discrete.discrete_model import (Poisson, Logit, Probit,
17 MNLogit, NegativeBinomial,
18 GeneralizedPoisson,
/usr/local/lib/python3.6/dist-packages/statsmodels/discrete/discrete_model.py in <module>()
43
44 from statsmodels.base.l1_slsqp import fit_l1_slsqp
---> 45 from statsmodels.distributions import genpoisson_p
46
47 try:
/usr/local/lib/python3.6/dist-packages/statsmodels/distributions/__init__.py in <module>()
1 from .empirical_distribution import ECDF, monotone_fn_inverter, StepFunction
----> 2 from .edgeworth import ExpandedNormal
3 from .discrete import genpoisson_p, zipoisson, zigenpoisson, zinegbin
/usr/local/lib/python3.6/dist-packages/statsmodels/distributions/edgeworth.py in <module>()
5 import numpy as np
6 from numpy.polynomial.hermite_e import HermiteE
----> 7 from scipy.misc import factorial
8 from scipy.stats import rv_continuous
9 import scipy.special as special
ImportError: cannot import name 'factorial'
I just want to use seasonal ARIMA,if there is any other way please help me.
Thanks.
Seems like there is a version mismatch of scipy module. Try downgrading scipy module.
In windows execute the following command in Administrative mode,
pip3 install --user scipy==1.2.0
If you're using Linux,
python3.6 -m pip install scipy==1.2 --upgrade

Error importing 'getargspec' statsmodels

I'm trying to do a logistic regression using statsmodels & an unable to import. I'm using statsmodels v0.8.0 with Python 3.x in a Jupyter notebook. How am I able to import correctly?
ImportError Traceback (most recent call last)
<ipython-input-47-6030a6549dc0> in <module>()
----> 1 import statsmodels.api as sm
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/api.py in <module>()
3 from . import tools
4 from .tools.tools import add_constant, categorical
----> 5 from . import regression
6 from .regression.linear_model import OLS, GLS, WLS, GLSAR
7 from .regression.recursive_ls import RecursiveLS
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/regression/__init__.py in <module>()
----> 1 from .linear_model import yule_walker
2
3 from statsmodels import NoseWrapper as Tester
4 test = Tester().test
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/regression/linear_model.py in <module>()
51 cache_readonly,
52 cache_writable)
---> 53 import statsmodels.base.model as base
54 import statsmodels.base.wrapper as wrap
55 from statsmodels.emplike.elregress import _ELRegOpts
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/base/model.py in <module>()
8 from statsmodels.stats.contrast import ContrastResults, WaldTestResults
9 from statsmodels.tools.decorators import resettable_cache, cache_readonly
---> 10 import statsmodels.base.wrapper as wrap
11 from statsmodels.tools.numdiff import approx_fprime
12 from statsmodels.tools.sm_exceptions import ValueWarning, \
/Applications/anaconda/lib/python3.6/site-packages/statsmodels/base/wrapper.py in <module>()
3
4 import numpy as np
----> 5 from statsmodels.compat.python import get_function_name, iteritems, getargspec
6
7 class ResultsWrapper(object):
ImportError: cannot import name 'getargspec'

Resources