I have had problems with using matplotlib after a Windows update. I'm running Windows 7 Service Pack 1 32 bit and I installed Python and matplotlib as part of Python(x,y)-2.7.6.1. The problem appears related to FreeType, as the import fails on ft2font as shown in the stack trace below:
In [1]: import matplotlib
In [2]: matplotlib.use('agg')
In [3]: import matplotlib.pyplot as plt
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-3-eff513f636fd> in <module>()
----> 1 import matplotlib.pyplot as plt
C:\Python27\lib\site-packages\matplotlib\pyplot.py in <module>()
22
23 import matplotlib
---> 24 import matplotlib.colorbar
25 from matplotlib import _pylab_helpers, interactive
26 from matplotlib.cbook import dedent, silent_list, is_string_like, is_numlike
C:\Python27\lib\site-packages\matplotlib\colorbar.py in <module>()
27 import matplotlib.artist as martist
28 import matplotlib.cbook as cbook
---> 29 import matplotlib.collections as collections
30 import matplotlib.colors as colors
31 import matplotlib.contour as contour
C:\Python27\lib\site-packages\matplotlib\collections.py in <module>()
21 import matplotlib.artist as artist
22 from matplotlib.artist import allow_rasterization
---> 23 import matplotlib.backend_bases as backend_bases
24 import matplotlib.path as mpath
25 from matplotlib import _path
C:\Python27\lib\site-packages\matplotlib\backend_bases.py in <module>()
48
49 import matplotlib.tight_bbox as tight_bbox
---> 50 import matplotlib.textpath as textpath
51 from matplotlib.path import Path
52 from matplotlib.cbook import mplDeprecation
C:\Python27\lib\site-packages\matplotlib\textpath.py in <module>()
9 from matplotlib.path import Path
10 from matplotlib import rcParams
---> 11 import matplotlib.font_manager as font_manager
12 from matplotlib.ft2font import FT2Font, KERNING_DEFAULT, LOAD_NO_HINTING
13 from matplotlib.ft2font import LOAD_TARGET_LIGHT
C:\Python27\lib\site-packages\matplotlib\font_manager.py in <module>()
51 import matplotlib
52 from matplotlib import afm
---> 53 from matplotlib import ft2font
54 from matplotlib import rcParams, get_cachedir
55 from matplotlib.cbook import is_string_like
ImportError: DLL load failed: The specified procedure could not be found.
I have tried reinstalling Python(x,y), but this did not resolve the problem.
From other answers on Stackoverflow I have learned that common failures here include missing msvcr90.dll and msvcp90.dll files. I downloaded Dependency Walker and opened c:\Python27\Lib\site-packages\matplotlib\FT2FONT.PYD. This showed issues with these files and with libbz2.dll. I downloaded and copied these files to c:\windows\system32.
I have also tried checking my PATH and PYTHONPATH environment variables, but they appear to reference my Python install correctly:
PATH: C:\Python27\Lib\site-packages\PyQt4;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\Novell\GroupWise;C:\Program Files\MiKTeX 2.9\miktex\bin\;C:\Program Files\Microsoft SQL Server\80\Tools\Binn\;C:\Program Files\Microsoft SQL Server\110\Tools\Binn\;C:\Program Files\Common Files\AspenTech Shared\;C:\Python27;C:\Python27\DLLs;C:\Python27\Scripts;C:\Python27\gnuplot\binary;C:\Program Files\pythonxy\SciTE-3.3.2-3;C:\Program Files\pythonxy\console;C:\MinGW32-xy\bin;C:\Python27\Lib\site-packages\vtk
PYTHONPATH: c:\Python27\DLLs
The problem manifests even when only using the Agg backend as shown in the session above, so I don't think it has anything to do with Qt or tk.
It appears that the problem was caused by an application installing a different/incompatible version of BZ2 in C:\Windows\System32\libbz2.dll. This was being used instead of the dll of the same name in the Python27 directory installed by Python(x,y). This is how the situation showed up in Dependency Walker:
You can see that there is something wrong with libbz2.dll even though Dependency Walker doesn't list it as a dependency error as such. Renaming or deleting the version in C:\Windows\System32\ caused the dependency to be resolved by the version in c:\Python27\DLLs.
Related
I am using python from a anaconda installation and using the python
notebook. From the jupyer notebook (ipython) I import fssa like:
import fssa
I get the following error message (see below).
Any help from you will be appreciated.
I have tried uninstalling and reinstalling scipy, numpy, and fssa and reinstalling
them, but the problem seems to remain.
ImportError Traceback (most recent call last)
/tmp/ipykernel_218856/781571052.py in <module>
----> 1 import fssa
~/anaconda3/lib/python3.9/site-packages/fssa/__init__.py in <module>
82
83 import pkg_resources
---> 84 from .fssa import scaledata, quality, autoscale
85
86 __version__ = pkg_resources.get_distribution(__name__).version
~/anaconda3/lib/python3.9/site-packages/fssa/fssa.py in <module>
46 import scipy.optimize
47
---> 48 from .optimize import _minimize_neldermead
49
50
~/anaconda3/lib/python3.9/site-packages/fssa/optimize.py in <module>
11 import numpy
12 from numpy import asfarray
---> 13 from scipy.optimize.optimize import (OptimizeResult,
14 _status_message, wrap_function)
15
ImportError: cannot import name 'wrap_function' from 'scipy.optimize.optimize'
(/home/debasish/anaconda3/lib/python3.9/site-packages/scipy/optimize/optimize.py)
I was trying to perform EDA in Iris Dataset on Jupyter Notebook and I was trying to import these libraries but I keep running into this error. Please help.
I have tried pip install --upgrade pip in my Anaconda command prompt and it responds to me with
Requirement already satisfied: pip in c:\users\aarushi\anaconda3\lib\site-packages (21.2.4)
I also tried pip install Pillow but it responded with
Requirement already satisfied: Pillow in c:\users\aarushi\anaconda3\lib\site-packages (8.3.1)
Also tried pip install --upgrade pip and the response-
Requirement already satisfied: pip in c:\users\aarushi\anaconda3\lib\site-packages (21.2.4)
I also installed IntelliJ, Visual Studio, Weka on my system.
Here is my code-
import os
import matplotlib
import seaborn as sns
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
<ipython-input-1-efa48e6030a2> in <module>
3 import os
4 import matplotlib
----> 5 import seaborn as sns
~\anaconda3\lib\site-packages\seaborn\__init__.py in <module>
1 # Import seaborn objects
----> 2 from .rcmod import * # noqa: F401,F403
3 from .utils import * # noqa: F401,F403
4 from .palettes import * # noqa: F401,F403
5 from .relational import * # noqa: F401,F403
~\anaconda3\lib\site-packages\seaborn\rcmod.py in <module>
5 import matplotlib as mpl
6 from cycler import cycler
----> 7 from . import palettes
8
9
~\anaconda3\lib\site-packages\seaborn\palettes.py in <module>
7 from .external import husl
8
----> 9 from .utils import desaturate, get_color_cycle
10 from .colors import xkcd_rgb, crayons
11
~\anaconda3\lib\site-packages\seaborn\utils.py in <module>
12 import matplotlib as mpl
13 import matplotlib.colors as mplcol
---> 14 import matplotlib.pyplot as plt
15 from matplotlib.cbook import normalize_kwargs
16
~\anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>
34 from cycler import cycler
35 import matplotlib
---> 36 import matplotlib.colorbar
37 import matplotlib.image
38 from matplotlib import rcsetup, style
~\anaconda3\lib\site-packages\matplotlib\colorbar.py in <module>
42 import matplotlib.collections as collections
43 import matplotlib.colors as colors
---> 44 import matplotlib.contour as contour
45 import matplotlib.cm as cm
46 import matplotlib.gridspec as gridspec
~\anaconda3\lib\site-packages\matplotlib\contour.py in <module>
15 import matplotlib.collections as mcoll
16 import matplotlib.font_manager as font_manager
---> 17 import matplotlib.text as text
18 import matplotlib.cbook as cbook
19 import matplotlib.mathtext as mathtext
~\anaconda3\lib\site-packages\matplotlib\text.py in <module>
14 from .font_manager import FontProperties
15 from .patches import FancyArrowPatch, FancyBboxPatch, Rectangle
---> 16 from .textpath import TextPath # Unused, but imported by others.
17 from .transforms import (
18 Affine2D, Bbox, BboxBase, BboxTransformTo, IdentityTransform, Transform)
~\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>
25
26 import numpy as np
---> 27 from PIL import Image
28 from pyparsing import (
29 Combine, Empty, FollowedBy, Forward, Group, Literal, oneOf, OneOrMore,
ModuleNotFoundError: No module named 'PIL'
I solved this by uninstalling Anaconda and installing it again. I faced this problem initially because I had downloaded multiple environments. I suggest to properly uninstall Anaconda by searching on the web.
Yes, I also got this error.
Did you install the seaborn after jupyter notebook opened?
You should restart the kernel from the top menu Kernel > Restart kernel.
<ipython-input-8-8ef302d419f0> in <module>
1 from netCDF4 import Dataset
2 import numpy
----> 3 from SkewTplus.sounding import sounding
~\Anaconda3\lib\site-packages\SkewTplus\sounding.py in <module>
19
20 from SkewTplus.`enter code here`errorHandling import fatalError
---> 21 from SkewTplus.skewT import figure
22
23
~\Anaconda3\lib\site-packages\SkewTplus\skewT.py in <module>
23 from matplotlib.axes import Axes
24 from matplotlib.backends import pylab_setup
---> 25 from matplotlib.cbook import is_string_like
26 from matplotlib.figure import Figure
27 from matplotlib.projections import register_projection
ImportError: cannot import name 'is_string_like' from 'matplotlib.cbook'
(C:\Users\User\Anaconda3\lib\site-packages\matplotlib\cbook\__init__.py)
I got an error when I import SkewTplus. I don't know what to do. I have tried reinstalling matplotlib but the problem doesn't go away.
I met the same error and solved it by reinstalling it again.Make sure using conda and pip to reinstall the package and then reinstall it again.
pip uninstall matplotlib
conda uninstall matplotlib
Having a problem importing matplotlib.pyplot into Jupyter notebook.
I uninstalled matplotlib (and seaborn) and reinstalled them again. But that didn't solve the problem.
The exact code however works in my second computer without problems.
I researched stackoverflow, and tried one thing that was suggested (please see bottom of post) - that still gave the exact same error.
Here's some relevant info
Platform : win-64, Windows 7 Enterprise
Conda version : 4.4.7
Conda-build version : 3.0.27
Python version : 3.6.4.final.0
JupyterLab : v0.27.0
Matplotlib version 2.1.2
Here's what I am trying to run:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
%matplotlib inline
I get the error shown below:
Pyplot_error
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-1-d2e7a3f2c9b4> in <module>()
1 import pandas as pd
2 import numpy as np
----> 3 import matplotlib.pyplot as plt
---------------------------------------------------------------------------
4 import seaborn as sns
5 get_ipython().run_line_magic('matplotlib', 'inline')
~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>()
30 from cycler import cycler
31 import matplotlib
---> 32 import matplotlib.colorbar
---------------------------------------------------------------------------
33 from matplotlib import style
34 from matplotlib import _pylab_helpers, interactive
~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\colorbar.py in <module>()
34 import matplotlib.collections as collections
35 import matplotlib.colors as colors
---> 36 import matplotlib.contour as contour
---------------------------------------------------------------------------
37 import matplotlib.cm as cm
38 import matplotlib.gridspec as gridspec
~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\contour.py in <module>()
19 import matplotlib.colors as colors
20 import matplotlib.collections as mcoll
---> 21 import matplotlib.font_manager as font_manager
---------------------------------------------------------------------------
22 import matplotlib.text as text
23 import matplotlib.cbook as cbook
~\AppData\Local\Continuum\anaconda3\lib\site-packages\matplotlib\font_manager.py in <module>()
56
57 import matplotlib
---> 58 from matplotlib import afm, cbook, ft2font, rcParams, get_cachedir
---------------------------------------------------------------------------
59 from matplotlib.compat import subprocess
60 from matplotlib.fontconfig_pattern import (
ImportError: DLL load failed: The specified procedure could not be found.
---------------------------------------------------------------------------
I get the same error when I try
import matplotlib as mpl
mpl.use('tkagg')
import matplotlib.pyplot as plt
I have Anaconda installed on OS X. I am able to import sklearn from a python terminal and an IPython terminal. But when I try to import sklearn from a Jupyter notebook, I get the following error:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-4-8fd979e02004> in <module>()
----> 1 import sklearn
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/__init__.py in <module>()
55 else:
56 from . import __check_build
---> 57 from .base import clone
58 __check_build # avoid flakes unused variable error
59
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/base.py in <module>()
10 from scipy import sparse
11 from .externals import six
---> 12 from .utils.fixes import signature
13 from .utils.deprecation import deprecated
14 from .exceptions import ChangedBehaviorWarning as _ChangedBehaviorWarning
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/__init__.py in <module>()
9
10 from .murmurhash import murmurhash3_32
---> 11 from .validation import (as_float_array,
12 assert_all_finite,
13 check_random_state, column_or_1d, check_array,
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/validation.py in <module>()
16
17 from ..externals import six
---> 18 from ..utils.fixes import signature
19 from .deprecation import deprecated
20 from ..exceptions import DataConversionWarning as _DataConversionWarning
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/sklearn/utils/fixes.py in <module>()
288 from ._scipy_sparse_lsqr_backport import lsqr as sparse_lsqr
289 else:
--> 290 from scipy.sparse.linalg import lsqr as sparse_lsqr
291
292
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/__init__.py in <module>()
110 from __future__ import division, print_function, absolute_import
111
--> 112 from .isolve import *
113 from .dsolve import *
114 from .interface import *
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/__init__.py in <module>()
4
5 #from info import __doc__
----> 6 from .iterative import *
7 from .minres import minres
8 from .lgmres import lgmres
/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/iterative.py in <module>()
5 __all__ = ['bicg','bicgstab','cg','cgs','gmres','qmr']
6
----> 7 from . import _iterative
8
9 from scipy.sparse.linalg.interface import LinearOperator
ImportError: dlopen(/Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so, 2): Library not loaded: /usr/local/lib/libgcc_s.1.dylib
Referenced from: /Users/joe/anaconda/envs/data_env/lib/python3.5/site-packages/scipy/sparse/linalg/isolve/_iterative.so
Reason: image not found
I can import numpy, scipy, and pandas fine from the Jupyter notebook. It is just sklearn that fails.
I have also tried creating a new conda environment (conda create -n test_env jupyter notebook matplotlib scipy numpy pandas scikit-learn), but the error persists in the new environment as well.
I managed to figure out what was going on, so I'll post my solution here in case anyone else runs into the same problem. As it turns out, I had modified the DYLD_FALLBACK_LIBRARY_PATH environment variable in my .bashrc file when I had installed another piece of software. Restoring this environment variable to its default fixed the problem for me.
(Incidentally, scikit-learn was failing to import in a standard Python terminal as well. I didn't initially realize this because I was testing the Python terminal in an environment in which I had accidentally restored the environment variables to their defaults, overwriting the change I had made in my .bashrc file.)