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?
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'**
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.
Using Jupyter notebook via Anaconda2 on a Windows7 OS 64-bit launching it with GraphLabCreate. Getting the following error when executing the command "import matplotlib.pyplot as plt".
Is it anything to do with the environmental variables as I'm using GraphLabCreate? They have the following from a tool bar command selection:
set "PATH=C:\Users\Owner\Anaconda2;C:\Users\Owner\Anaconda2\Scripts;%PATH%"
I've gone ahead and checked the environmental variables and they are listed as above (except for the %PATH% part). Here are the PATH variables on my computer:
C:\Users\Owner\Anaconda2;C:\Users\Owner\Anaconda2\Scripts;C:\Users\Owner\Anaconda2\Library\bin;C:\Program Files\R\R-3.4.2\bin\x64
Here is the entire error output:
UnicodeDecodeError Traceback (most recent call last)
<ipython-input-9-6f467123fe04> in <module>()
----> 1 import matplotlib.pyplot
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\pyplot.py in <module>()
27 from cycler import cycler
28 import matplotlib
---> 29 import matplotlib.colorbar
30 from matplotlib import style
31 from matplotlib import _pylab_helpers, interactive
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\colorbar.py in <module>()
32 import matplotlib.artist as martist
33 import matplotlib.cbook as cbook
---> 34 import matplotlib.collections as collections
35 import matplotlib.colors as colors
36 import matplotlib.contour as contour
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\collections.py in <module>()
25 import matplotlib.artist as artist
26 from matplotlib.artist import allow_rasterization
---> 27 import matplotlib.backend_bases as backend_bases
28 import matplotlib.path as mpath
29 from matplotlib import _path
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\backend_bases.py in <module>()
60
61 import matplotlib.tight_bbox as tight_bbox
---> 62 import matplotlib.textpath as textpath
63 from matplotlib.path import Path
64 from matplotlib.cbook import mplDeprecation, warn_deprecated
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\textpath.py in <module>()
13 from matplotlib.path import Path
14 from matplotlib import rcParams
---> 15 import matplotlib.font_manager as font_manager
16 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
17 from matplotlib.ft2font import LOAD_TARGET_LIGHT
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\font_manager.py in <module>()
1419 verbose.report("Using fontManager instance from %s" % _fmcache)
1420 except:
-> 1421 _rebuild()
1422 else:
1423 _rebuild()
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\font_manager.py in _rebuild()
1404 def _rebuild():
1405 global fontManager
-> 1406 fontManager = FontManager()
1407 if _fmcache:
1408 pickle_dump(fontManager, _fmcache)
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\font_manager.py in __init__(self, size, weight)
1042 # Load TrueType fonts and create font dictionary.
1043
-> 1044 self.ttffiles = findSystemFonts(paths) + findSystemFonts()
1045 self.defaultFamily = {
1046 'ttf': 'Bitstream Vera Sans',
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\font_manager.py in findSystemFonts(fontpaths, fontext)
311 fontpaths = [fontdir]
312 # now get all installed fonts directly...
--> 313 for f in win32InstalledFonts(fontdir):
314 base, ext = os.path.splitext(f)
315 if len(ext)>1 and ext[1:].lower() in fontexts:
C:\Users\Owner\Anaconda2\envs\gl-env\lib\site-packages\matplotlib\font_manager.py in win32InstalledFonts(directory, fontext)
228 continue
229 if not os.path.dirname(direc):
--> 230 direc = os.path.join(directory, direc)
231 direc = os.path.abspath(direc).lower()
232 if os.path.splitext(direc)[1][1:] in fontext:
C:\Users\Owner\Anaconda2\envs\gl-env\lib\ntpath.pyc in join(path, *paths)
83 if result_path and result_path[-1] not in '\\/':
84 result_path = result_path + '\\'
---> 85 result_path = result_path + p_path
86 ## add separator between UNC and non-absolute path
87 if (result_path and result_path[0] not in '\\/' and
UnicodeDecodeError: 'ascii' codec can't decode byte 0x80 in position 7: ordinal not in range(128)
After some fixing my PATH variable to get some library installs to work , I'm finding that my IPython Notebook (Enthought Canopy on Ubuntu 14.04) throws the following error when using the %matplotlib magic command:
ImportError: /home/joe/Enthought/Canopy_64bit/User/bin/../lib/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3)
I'm also getting this error when trying to install python-bio-formats, pims, and pylibtiff.
Again, any ideas are appreciated.
EDIT: Full error traceback:
ImportError Traceback (most recent call last)
<ipython-input-1-3042faeb62d7> in <module>()
----> 1 get_ipython().magic(u'matplotlib')
2 #import cv2
3 #import numpy as np
4 #import pandas as pd
5 #import os
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in magic(self, arg_s)
2203 magic_name, _, magic_arg_s = arg_s.partition(' ')
2204 magic_name = magic_name.lstrip(prefilter.ESC_MAGIC)
-> 2205 return self.run_line_magic(magic_name, magic_arg_s)
2206
2207 #-------------------------------------------------------------------------
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in run_line_magic(self, magic_name, line)
2124 kwargs['local_ns'] = sys._getframe(stack_depth).f_locals
2125 with self.builtin_trap:
-> 2126 result = fn(*args,**kwargs)
2127 return result
2128
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc in matplotlib(self, line)
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/magic.pyc in <lambda>(f, *a, **k)
191 # but it's overkill for just that one bit of state.
192 def magic_deco(arg):
--> 193 call = lambda f, *a, **k: f(*a, **k)
194
195 if callable(arg):
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/magics/pylab.pyc in matplotlib(self, line)
78 """
79 args = magic_arguments.parse_argstring(self.matplotlib, line)
---> 80 gui, backend = self.shell.enable_matplotlib(args.gui)
81 self._show_matplotlib_backend(args.gui, backend)
82
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/interactiveshell.pyc in enable_matplotlib(self, gui)
2929 """
2930 from IPython.core import pylabtools as pt
-> 2931 gui, backend = pt.find_gui_and_backend(gui, self.pylab_gui_select)
2932
2933 if gui != 'inline':
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/IPython/core/pylabtools.pyc in find_gui_and_backend(gui, gui_select)
250 """
251
--> 252 import matplotlib
253
254 if gui and gui != 'auto':
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/__init__.py in <module>()
177 # cbook must import matplotlib only within function
178 # definitions, so it is safe to import from it here.
--> 179 from matplotlib.cbook import is_string_like
180 from matplotlib.compat import subprocess
181
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/matplotlib/cbook.py in <module>()
30 from weakref import ref, WeakKeyDictionary
31
---> 32 import numpy as np
33 import numpy.ma as ma
34
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/__init__.pyc in <module>()
168 return loader(*packages, **options)
169
--> 170 from . import add_newdocs
171 __all__ = ['add_newdocs',
172 'ModuleDeprecationWarning',
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/add_newdocs.py in <module>()
11 from __future__ import division, absolute_import, print_function
12
---> 13 from numpy.lib import add_newdoc
14
15 ###############################################################################
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/__init__.py in <module>()
16
17 from . import scimath as emath
---> 18 from .polynomial import *
19 #import convertcode
20 from .utils import *
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/lib/polynomial.py in <module>()
17 from numpy.lib.function_base import trim_zeros, sort_complex
18 from numpy.lib.type_check import iscomplex, real, imag
---> 19 from numpy.linalg import eigvals, lstsq, inv
20
21 class RankWarning(UserWarning):
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/__init__.py in <module>()
49 from .info import __doc__
50
---> 51 from .linalg import *
52
53 from numpy.testing import Tester
/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/numpy/linalg/linalg.py in <module>()
27 )
28 from numpy.lib import triu, asfarray
---> 29 from numpy.linalg import lapack_lite, _umath_linalg
30 from numpy.matrixlib.defmatrix import matrix_power
31 from numpy.compat import asbytes
ImportError: /home/joe/Enthought/Canopy_64bit/User/bin/../lib/libgfortran.so.3: version `GFORTRAN_1.4' not found (required by /usr/lib/liblapack.so.3)
Full PATH (from echo $PATH):
/home/joe/Enthought/Canopy_64bit/User/bin:
/home/joe/Enthought/Canopy_64bit/User/bin:
/usr/local/sbin:
/usr/local/bin:
/usr/sbin:
/usr/bin:
/sbin:
/bin:
/usr/games:
/usr/local/games
sys.path:
['', '/home/joe/Enthought/Canopy_64bit/User/src/svn',
'/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/pims',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python27.zip',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/plat-linux2',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-tk',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-old',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/lib-dynload',
'/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages',
'/home/joe/Enthought/Canopy_64bit/User/lib/python2.7/site-packages/PIL',
'/home/joe/opencv-2.4.9',
'/home/joe/Canopy/appdata/canopy-1.4.1.1975.rh5-x86_64/lib/python2.7/site-packages']
I was able to resolve this error by following the steps outlined here (specifically, steps 3-5): https://support.enthought.com/entries/23580651-Uninstalling-and-resetting-Canopy.
When re-attempting to install pims (https://github.com/soft-matter/pims) using pip (command: pip install --upgrade http://github.com/soft-matter/pims/zipball/master), the problem is able to be replicated. Odd.
I'm also getting a problem when trying to install pylibtiff via its setup.py script, but I will post this in another SO post, further detailing the error.
This might be late, but you can try the following thread
https://github.com/ContinuumIO/anaconda-issues/issues/686
Specifically the one by Zarhid:
conda remove libgfortran
conda install libgcc --force
replace conda with pip and modify accordingly. Worked for me