AttributeError: module 'matplotlib.cbook' has no attribute '_get_data_path' - python

When trying to run 2 libraries on jupyter. I am running the following code:
import pandas as pd
from pandas_profiling import ProfileReport
This is returning the following error:
AttributeError Traceback (most recent call last)
<ipython-input-31-98f09099f855> in <module>
1 import pandas as pd
----> 2 from pandas_profiling import ProfileReport
~\Anaconda3\lib\site-packages\pandas_profiling\__init__.py in <module>
5
6 from pandas_profiling.config import Config, config
----> 7 from pandas_profiling.controller import pandas_decorator
8 from pandas_profiling.profile_report import ProfileReport
9 from pandas_profiling.version import __version__
~\Anaconda3\lib\site-packages\pandas_profiling\controller\pandas_decorator.py in <module>
2 from pandas import DataFrame
3
----> 4 from pandas_profiling.__init__ import ProfileReport
5
6
~\Anaconda3\lib\site-packages\pandas_profiling\__init__.py in <module>
6 from pandas_profiling.config import Config, config
7 from pandas_profiling.controller import pandas_decorator
----> 8 from pandas_profiling.profile_report import ProfileReport
9 from pandas_profiling.version import __version__
10
.
.
.
~\Anaconda3\lib\site-packages\matplotlib\textpath.py in <module>
9 from matplotlib.font_manager import FontProperties, get_font
10 from matplotlib.ft2font import LOAD_NO_HINTING, LOAD_TARGET_LIGHT
---> 11 from matplotlib.mathtext import MathTextParser
12 from matplotlib.path import Path
13 from matplotlib.transforms import Affine2D
~\Anaconda3\lib\site-packages\matplotlib\mathtext.py in <module>
1057
1058
-> 1059 class StandardPsFonts(Fonts):
1060 """
1061 Use the standard postscript fonts for rendering to backend_ps
~\Anaconda3\lib\site-packages\matplotlib\mathtext.py in StandardPsFonts()
1064 one requires the Ps backend.
1065 """
-> 1066 basepath = str(cbook._get_data_path('fonts/afm'))
1067
1068 fontmap = {
AttributeError: module 'matplotlib.cbook' has no attribute '_get_data_path'
My matplotlib has always worked fine without the jupyter. I have tried reinstall of matplotlib. but still getting the same error.

Related

why am I getting this error from importing libraries?

I ran a Classification And Regression Tree (CART) code yesterday that worked perfectly. Today, I am getting the following error after importing the libraries below without changing anything.
import pandas as pd
import numpy as np
import seaborn as sn
from sklearn import datasets
from sklearn import metrics
from sklearn.tree import DecisionTreeClassifier
from sklearn.tree import DecisionTreeRegressor
from sklearn.model_selection import train_test_split
import matplotlib.pyplot as plt
from sklearn.preprocessing import LabelEncoder
from sklearn.tree import export_graphviz
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_7048/1297423964.py in <module>
5 import numpy as np
6 import seaborn as sn
----> 7 from sklearn import datasets
8 from sklearn import metrics
9 from sklearn.tree import DecisionTreeClassifier
~\Anaconda3\lib\site-packages\sklearn\datasets\__init__.py in <module>
20 from .lfw import fetch_lfw_pairs
21 from .lfw import fetch_lfw_people
---> 22 from .twenty_newsgroups import fetch_20newsgroups
23 from .twenty_newsgroups import fetch_20newsgroups_vectorized
24 from .mldata import fetch_mldata, mldata_filename
~\Anaconda3\lib\site-packages\sklearn\datasets\twenty_newsgroups.py in <module>
42 from .base import _fetch_remote
43 from .base import RemoteFileMetadata
---> 44 from ..feature_extraction.text import CountVectorizer
45 from ..preprocessing import normalize
46 from ..utils import deprecated
~\Anaconda3\lib\site-packages\sklearn\feature_extraction\__init__.py in <module>
8 from .hashing import FeatureHasher
9 from .image import img_to_graph, grid_to_graph
---> 10 from . import text
11
12 __all__ = ['DictVectorizer', 'image', 'img_to_graph', 'grid_to_graph', 'text',
~\Anaconda3\lib\site-packages\sklearn\feature_extraction\text.py in <module>
26
27 from ..base import BaseEstimator, TransformerMixin
---> 28 from ..preprocessing import normalize
29 from .hashing import FeatureHasher
30 from .stop_words import ENGLISH_STOP_WORDS
~\Anaconda3\lib\site-packages\sklearn\preprocessing\__init__.py in <module>
4 """
5
----> 6 from ._function_transformer import FunctionTransformer
7
8 from .data import Binarizer
~\Anaconda3\lib\site-packages\sklearn\preprocessing\_function_transformer.py in <module>
3 from ..base import BaseEstimator, TransformerMixin
4 from ..utils import check_array
----> 5 from ..utils.testing import assert_allclose_dense_sparse
6
7
~\Anaconda3\lib\site-packages\sklearn\utils\testing.py in <module>
716
717 try:
--> 718 import pytest
719
720 skip_if_32bit = pytest.mark.skipif(_IS_32BIT,
~\Anaconda3\lib\site-packages\pytest.py in <module>
4 """
5 from _pytest import __version__
----> 6 from _pytest.assertion import register_assert_rewrite
7 from _pytest.config import cmdline
8 from _pytest.config import hookimpl
~\Anaconda3\lib\site-packages\_pytest\assertion\__init__.py in <module>
4 import sys
5
----> 6 from _pytest.assertion import rewrite
7 from _pytest.assertion import truncate
8 from _pytest.assertion import util
~\Anaconda3\lib\site-packages\_pytest\assertion\rewrite.py in <module>
18 from _pytest._io.saferepr import saferepr
19 from _pytest._version import version
---> 20 from _pytest.assertion import util
21 from _pytest.assertion.util import ( # noqa: F401
22 format_explanation as _format_explanation,
~\Anaconda3\lib\site-packages\_pytest\assertion\util.py in <module>
3 from collections.abc import Sequence
4
----> 5 import _pytest._code
6 from _pytest import outcomes
7 from _pytest._io.saferepr import saferepr
~\Anaconda3\lib\site-packages\_pytest\_code\__init__.py in <module>
1 """ python inspection/code generation API """
----> 2 from .code import Code # noqa
3 from .code import ExceptionInfo # noqa
4 from .code import filter_traceback # noqa
5 from .code import Frame # noqa
~\Anaconda3\lib\site-packages\_pytest\_code\code.py in <module>
9
10 import attr
---> 11 import pluggy
12 import py
13
~\Anaconda3\lib\site-packages\pluggy\__init__.py in <module>
14 ]
15
---> 16 from .manager import PluginManager, PluginValidationError
17 from .callers import HookCallError
18 from .hooks import HookspecMarker, HookimplMarker
~\Anaconda3\lib\site-packages\pluggy\manager.py in <module>
4 import warnings
5
----> 6 import importlib_metadata
7
8
~\Anaconda3\lib\site-packages\importlib_metadata\__init__.py in <module>
464
465
--> 466 __version__ = version(__name__)
~\Anaconda3\lib\site-packages\importlib_metadata\__init__.py in version(package)
431 "Version" metadata key.
432 """
--> 433 return distribution(package).version
434
435
~\Anaconda3\lib\site-packages\importlib_metadata\__init__.py in distribution(package)
404 :return: A ``Distribution`` instance (or subclass thereof).
405 """
--> 406 return Distribution.from_name(package)
407
408
~\Anaconda3\lib\site-packages\importlib_metadata\__init__.py in from_name(cls, name)
173 """
174 for resolver in cls._discover_resolvers():
--> 175 dists = resolver(name)
176 dist = next(dists, None)
177 if dist is not None:
~\Anaconda3\lib\site-packages\setuptools\_vendor\importlib_metadata\__init__.py in find_distributions(self, context)
884 of directories ``context.path``.
885 """
--> 886 found = self._search_paths(context.name, context.path)
887 return map(PathDistribution, found)
888
AttributeError: 'str' object has no attribute 'name'
AttributeError: 'str' object has no attribute 'name'
after running each line singly, I noticed the error started at line 4 (from sklearn import datasets)
why is this?

No model PIL is found

pip install Pillow
Requirement already satisfied: Pillow in e:\finalproject\fyp\lib\site-packages (9.0.1)
BUT still get error
ModuleNotFoundError Traceback (most recent call last)
e:\FinalProject\ImageDetection.ipynb Cell 9' in <cell line: 4>()
3 from object_detection.utils import label_map_util
----> 4 from object_detection.utils import visualization_utils as viz_utils
5 from object_detection.builders import model_builder
6 from object_detection.utils import config_util```
File e:\FinalProject\fyp\lib\site-packages\object_detection-0.1-py3.10.egg\object_detection\utils\visualization_utils.py:29, in <module>
```27 import collections
28 # Set headless-friendly backend.
---> 29 import matplotlib; matplotlib.use('Agg') # pylint: disable=multiple-statements
30 import matplotlib.pyplot as plt # pylint: disable=g-import-not-at-top
31 import numpy as np```
File e:\FinalProject\fyp\lib\site-packages\matplotlib\__init__.py:109, in <module>
``` 105 from packaging.version import parse as parse_version
107 # cbook must import matplotlib only within function
108 # definitions, so it is safe to import from it here.
--> 109 from . import _api, _version, cbook, docstring, rcsetup
110 from matplotlib.cbook import MatplotlibDeprecationWarning, sanitize_sequence
111 from matplotlib.cbook import mplDeprecation # deprecated```
File e:\FinalProject\fyp\lib\site-packages\matplotlib\rcsetup.py:27, in <module>
``` 25 from matplotlib import _api, cbook
26 from matplotlib.cbook import ls_mapper
---> 27 from matplotlib.colors import Colormap, is_color_like
28 from matplotlib.fontconfig_pattern import parse_fontconfig_pattern
29 from matplotlib._enums import JoinStyle, CapStyle```
File e:\FinalProject\fyp\lib\site-packages\matplotlib\colors.py:51, in <module>
``` 49 from numbers import Number
50 import re
---> 51 from PIL import Image
52 from PIL.PngImagePlugin import PngInfo
54 import matplotlib as mpl```
**ModuleNotFoundError: No module named 'PIL'**

While trying to use sklearn in Jupyter Notebook, it gives me an error. Does anyone know how to solve it?

These are the commands I am trying to launch
from sklearn.datasets import load_boston
boston = load_boston()
boston
And it returns me a plenty of errors
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_16972/433790950.py in <module>
2 import numpy
3 import matplotlib
----> 4 from sklearn.datasets import load_boston
5 boston = load_boston()
6 boston
~\anaconda3\lib\site-packages\sklearn\__init__.py in <module>
80 from . import _distributor_init # noqa: F401
81 from . import __check_build # noqa: F401
---> 82 from .base import clone
83 from .utils._show_versions import show_versions
84
~\anaconda3\lib\site-packages\sklearn\base.py in <module>
15 from . import __version__
16 from ._config import get_config
---> 17 from .utils import _IS_32BIT
18 from .utils._tags import (
19 _DEFAULT_TAGS,
~\anaconda3\lib\site-packages\sklearn\utils\__init__.py in <module>
21
22 from .murmurhash import murmurhash3_32
---> 23 from .class_weight import compute_class_weight, compute_sample_weight
24 from . import _joblib
25 from ..exceptions import DataConversionWarning
~\anaconda3\lib\site-packages\sklearn\utils\class_weight.py in <module>
5 import numpy as np
6
----> 7 from .validation import _deprecate_positional_args
8
9
~\anaconda3\lib\site-packages\sklearn\utils\validation.py in <module>
20 # mypy error: Module 'numpy.core.numeric' has no attribute 'ComplexWarning'
21 from numpy.core.numeric import ComplexWarning # type: ignore
---> 22 import joblib
23
24 from contextlib import suppress
~\anaconda3\lib\site-packages\joblib\__init__.py in <module>
118 from .numpy_pickle import load
119 from .compressor import register_compressor
--> 120 from .parallel import Parallel
121 from .parallel import delayed
122 from .parallel import cpu_count
~\anaconda3\lib\site-packages\joblib\parallel.py in <module>
24 from .logger import Logger, short_format_time
25 from .disk import memstr_to_bytes
---> 26 from ._parallel_backends import (FallbackToBackend, MultiprocessingBackend,
27 ThreadingBackend, SequentialBackend,
28 LokyBackend)
~\anaconda3\lib\site-packages\joblib\_parallel_backends.py in <module>
15
16 if mp is not None:
---> 17 from .pool import MemmappingPool
18 from multiprocessing.pool import ThreadPool
19 from .executor import get_memmapping_executor
~\anaconda3\lib\site-packages\joblib\pool.py in <module>
29 from io import BytesIO
30
---> 31 from ._memmapping_reducer import get_memmapping_reducers
32 from ._memmapping_reducer import TemporaryResourcesManager
33 from ._multiprocessing_helpers import mp, assert_spawning
~\anaconda3\lib\site-packages\joblib\_memmapping_reducer.py in <module>
35 from .backports import make_memmap
36 from .disk import delete_folder
---> 37 from .externals.loky.backend import resource_tracker
38
39 # Some system have a ramdisk mounted by default, we can use it instead of /tmp
~\anaconda3\lib\site-packages\joblib\externals\loky\backend\resource_tracker.py in <module>
47 import threading
48
---> 49 from . import spawn
50 from multiprocessing import util
51
~\anaconda3\lib\site-packages\joblib\externals\loky\backend\spawn.py in <module>
19 else:
20 import msvcrt
---> 21 from .reduction import duplicate
22 WINEXE = (sys.platform == 'win32' and getattr(sys, 'frozen', False))
23 WINSERVICE = sys.executable.lower().endswith("pythonservice.exe")
~\anaconda3\lib\site-packages\joblib\externals\loky\backend\reduction.py in <module>
123 # global variable to change the pickler behavior
124 try:
--> 125 from joblib.externals import cloudpickle # noqa: F401
126 DEFAULT_ENV = "cloudpickle"
127 except ImportError:
~\anaconda3\lib\site-packages\joblib\externals\cloudpickle\__init__.py in <module>
2
3
----> 4 from .cloudpickle import * # noqa
5 from .cloudpickle_fast import CloudPickler, dumps, dump # noqa
6
~\anaconda3\lib\site-packages\joblib\externals\cloudpickle\cloudpickle.py in <module>
62
63 try: # pragma: no branch
---> 64 import typing_extensions as _typing_extensions
65 from typing_extensions import Literal, Final
66 except ImportError:
~\anaconda3\lib\site-packages\typing_extensions.py in <module>
2141
2142 #_TypeAliasForm
-> 2143 def TypeAlias(self, parameters):
2144 """Special marker indicating that an assignment should
2145 be recognized as a proper type alias definition by type
TypeError: __init__() missing 1 required positional argument: 'doc'
Honestly I am not even able to understand which is exactly the error. I had tried to reinstall again Anaconda but the situation seems unchanged. It seems that the error relies in the packages but I don't know how I could solve it.
Thanks in advance and sorry for the unprecise question.

Identify which DLL is missing in Jupyter import declaration

Only when run in Jupyter, scikit learn throws an error saying it cannot find a DLL. There are several answers to this question in SO, none worked for me, but in most cases the solution was to copy the DLL manually. How can I tell from the stack trace below which DLL is missing?
I use Miniconda 3 to install libraries and scikit learn works perfectly in PyCharm IDE.
from sklearn.ensemble import RandomForestClassifier
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-019d114f89a0> in <module>
----> 1 from sklearn.ensemble import RandomForestClassifier
~\Miniconda3\lib\site-packages\sklearn\__init__.py in <module>
74 else:
75 from . import __check_build
---> 76 from .base import clone
77 from .utils._show_versions import show_versions
78
~\Miniconda3\lib\site-packages\sklearn\base.py in <module>
14
15 from . import __version__
---> 16 from .utils import _IS_32BIT
17
18 _DEFAULT_TAGS = {
~\Miniconda3\lib\site-packages\sklearn\utils\__init__.py in <module>
18 from ..exceptions import DataConversionWarning
19 from .deprecation import deprecated
---> 20 from .validation import (as_float_array,
21 assert_all_finite,
22 check_random_state, column_or_1d, check_array,
~\Miniconda3\lib\site-packages\sklearn\utils\validation.py in <module>
19 from numpy.core.numeric import ComplexWarning
20
---> 21 from .fixes import _object_dtype_isnan
22 from .. import get_config as _get_config
23 from ..exceptions import NonBLASDotWarning
~\Miniconda3\lib\site-packages\sklearn\utils\fixes.py in <module>
16 import scipy.sparse as sp
17 import scipy
---> 18 from scipy.sparse.linalg import lsqr as sparse_lsqr # noqa
19
20
~\Miniconda3\lib\site-packages\scipy\sparse\linalg\__init__.py in <module>
114 from .dsolve import *
115 from .interface import *
--> 116 from .eigen import *
117 from .matfuncs import *
118 from ._onenormest import *
~\Miniconda3\lib\site-packages\scipy\sparse\linalg\eigen\__init__.py in <module>
9 from __future__ import division, print_function, absolute_import
10
---> 11 from .arpack import *
12 from .lobpcg import *
13
~\Miniconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\__init__.py in <module>
20 from __future__ import division, print_function, absolute_import
21
---> 22 from .arpack import *
~\Miniconda3\lib\site-packages\scipy\sparse\linalg\eigen\arpack\arpack.py in <module>
43 __all__ = ['eigs', 'eigsh', 'svds', 'ArpackError', 'ArpackNoConvergence']
44
---> 45 from . import _arpack
46 import numpy as np
47 import warnings
ImportError: DLL load failed: The specified procedure could not be found.
With regards to stack trace, encapsulate your entire code with try except block. Code below prints out the script name, line number of the error code and type of error. str(e) allows a deeper dive into tracing of the stack.
import os, sys
try:
# Place your code here
except Exception as e:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print("Exception occurred while processing: {}, line {}, {}".format(fname, exc_tb.tb_lineno, exc_type))
print("Exception occurred: "+ str(e))

Python TensorFlow

I am having a problem with instaling Tensorflow module, I've done my research but I was unable to find the solution Online.
I am running only the tensorflow example code.
import numpy as np
import os
import six.moves.urllib as urllib
import sys
import tarfile
import tensorflow as tf
import zipfile
from distutils.version import StrictVersion
from collections import defaultdict
from io import StringIO
from matplotlib import pyplot as plt
from PIL import Image
# This is needed since the notebook is stored in the object_detection folder.
sys.path.append("..")
from object_detection.utils import ops as utils_ops
if StrictVersion(tf.__version__) < StrictVersion('1.9.0'):
raise ImportError('Please upgrade your TensorFlow installation to v1.9.* or later!')
and this is the output:
FileNotFoundError Traceback (most recent call last)
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in <module>()
1352 try:
-> 1353 fontManager = json_load(_fmcache)
1354 if (not hasattr(fontManager, '_version') or
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in json_load(filename)
887 """
--> 888 with open(filename, 'r') as fh:
889 return json.load(fh, object_hook=_json_decode)
FileNotFoundError: [Errno 2] No such file or directory: 'C:\\Users\\Mestre\\.matplotlib\\fontlist-v300.json'
During handling of the above exception, another exception occurred:
TypeError Traceback (most recent call last)
<ipython-input-1-1e9eee4e6961> in <module>()
10 from collections import defaultdict
11 from io import StringIO
---> 12 from matplotlib import pyplot as plt
13 from PIL import Image
14
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\pyplot.py in <module>()
30 from cycler import cycler
31 import matplotlib
---> 32 import matplotlib.colorbar
33 import matplotlib.image
34 from matplotlib import rcsetup, style
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\colorbar.py in <module>()
30 import matplotlib.collections as collections
31 import matplotlib.colors as colors
---> 32 import matplotlib.contour as contour
33 import matplotlib.cm as cm
34 import matplotlib.gridspec as gridspec
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\contour.py in <module>()
16 import matplotlib.colors as mcolors
17 import matplotlib.collections as mcoll
---> 18 import matplotlib.font_manager as font_manager
19 import matplotlib.text as text
20 import matplotlib.cbook as cbook
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in <module>()
1361 raise
1362 except Exception:
-> 1363 _rebuild()
1364 else:
1365 _rebuild()
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in _rebuild()
1342 global fontManager
1343
-> 1344 fontManager = FontManager()
1345
1346 if _fmcache:
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in __init__(self, size, weight)
976 self.defaultFont = {}
977
--> 978 ttffiles = findSystemFonts(paths) + findSystemFonts()
979 self.defaultFont['ttf'] = next(
980 (fname for fname in ttffiles
c:\users\mestre\appdata\local\programs\python\python35\lib\site-packages\matplotlib\font_manager.py in findSystemFonts(fontpaths, fontext)
262 fontpaths = [win32FontDirectory()]
263 # now get all installed fonts directly...
--> 264 fontfiles.update(win32InstalledFonts(fontext=fontext))
265 else:
266 fontpaths = X11FontDirectories
TypeError: 'NoneType' object is not iterable
It seems a problem with matplotlib but I've already instaled that module, and compiled the protoc files and this is the third I've trying to install tensorflow but without sucess.
Thanks to all the lads who'll reply
Thanks again, Paula
It's a bug in matplotlib. In lib/matplotlib/font_manager.py you need to change the win32InstalledFonts function to return [] instead of return None.
Documented here:
https://github.com/matplotlib/matplotlib/pull/12174/files

Categories

Resources