can't import matplotlib.pyplot; DLL load failed - python

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

Related

ModuleNotFoundError: no module named Python Error

import numpy as np
from numpy.random import default_rng
import matplotlib.pyplot as plt
import line
from python import display
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In [12], line 3
1 import numpy as np
2 from numpy.random import default_rng
----> 3 import matplotlib.pyplot as plt
4 import line
5 from python import display
ModuleNotFoundError: No module named 'matplotlib'
import numpy as np
from numpy.random import default_rng
from python import display
import matplotlib.pyplot as plt
import line
---------------------------------------------------------------------------
ModuleNotFoundError Traceback (most recent call last)
Cell In [13], line 4
1 import numpy as np
2 from numpy.random import default_rng
----> 4 from python import display
5 import matplotlib.pyplot as plt
6 import line
ModuleNotFoundError: No module named 'python'
i wonna make graph...................................................................................
ModuleNotFoundError means there is a problem trying import a module into your application. Often this is because you don't have the module available locally (i.e. not installed). It can also be because you've mistyped the import statement or are trying to import the module using the wrong name.
In your case:
from python import display doesn't make much sense.
Python is not a package, as far as I'm aware. Where did this line of code come from? Where is the display() function you are trying to use?
----> 3 import matplotlib.pyplot as plt
ModuleNotFoundError: No module named 'matplotlib'
This means the matplotlib library is not installed.
You can install it using:
python3 -m pip install matplotlib

ModuleNotFoundError in importing matplotlib or seaborn

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.

AttributeError: partially initialized module 'pyproj' has no attribute 'network' (most likely due to a circular import)

I am trying to use geopandas but am getting the following error:
AttributeError: partially initialized module 'pyproj' has no attribute 'network' (most likely due to a circular import)
I am using Jupyter and am installing following dependencies
%conda install numpy
%conda install pandas
%pip install geopandas
%conda install -c plotly plotly
%conda install -c conda-forge pyarrow
%conda install scikit-learn
%pip install ipdb
%pip install --upgrade certifi
%pip install geopandas
I then import the following dependencies
import argparse
import os
import geopandas as gpd
import plotly.express as px
import plotly.graph_objects as go
import numpy as np
import pandas as pd
from ipdb import set_trace
from math import sin, cos, sqrt, atan2, radians
from pyod.models.lscp import LSCP
from pyod.models.lof import LOF
from pyod.utils.utility import standardizer
from pyod.utils.data import generate_data
from pyod.utils.data import evaluate_print
from pyod.utils.example import visualize
from scipy.stats import zscore
from sklearn.neighbors import BallTree, KDTree
from sklearn.cluster import DBSCAN
from sklearn.ensemble import IsolationForest
from sklearn.neighbors import LocalOutlierFactor
When I take out %pip install --upgrade certifi I get the following error:
AttributeError: module 'certifi' has no attribute 'where'
I get the following traceback for the certifi error:
AttributeError Traceback (most recent call last)
<ipython-input-2-c307bc851b37> in <module>
1 import argparse
2 import os
----> 3 import geopandas as gpd
4 import plotly.express as px
5 import plotly.graph_objects as go
~/miniconda3/lib/python3.9/site-packages/geopandas/__init__.py in <module>
----> 1 from geopandas._config import options # noqa
2
3 from geopandas.geoseries import GeoSeries # noqa
4 from geopandas.geodataframe import GeoDataFrame # noqa
5 from geopandas.array import points_from_xy # noqa
~/miniconda3/lib/python3.9/site-packages/geopandas/_config.py in <module>
124 use_pygeos = Option(
125 key="use_pygeos",
--> 126 default_value=_default_use_pygeos(),
127 doc=(
128 "Whether to use PyGEOS to speed up spatial operations. The default is True "
~/miniconda3/lib/python3.9/site-packages/geopandas/_config.py in _default_use_pygeos()
110
111 def _default_use_pygeos():
--> 112 import geopandas._compat as compat
113
114 return compat.USE_PYGEOS
~/miniconda3/lib/python3.9/site-packages/geopandas/_compat.py in <module>
6
7 import pandas as pd
----> 8 import pyproj
9 import shapely
10 import shapely.geos
~/miniconda3/lib/python3.9/site-packages/pyproj/__init__.py in <module>
78 warnings.warn(str(err))
79
---> 80 pyproj.network.set_ca_bundle_path()
~/miniconda3/lib/python3.9/site-packages/pyproj/network.py in set_ca_bundle_path(ca_bundle_path)
49 env_var_name in os.environ for env_var_name in env_var_names
50 ):
---> 51 ca_bundle_path = certifi.where()
52 else:
53 # reset CA Bundle path to use system settings
AttributeError: module 'certifi' has no attribute 'where'
I get the following error when I install certifi:
------ AttributeError Traceback (most recent call last) <ipython-input-5-c307bc851b37> in <module>
1 import argparse
2 import os
----> 3 import geopandas as gpd
4 import plotly.express as px
5 import plotly.graph_objects as go
~/miniconda3/lib/python3.9/site-packages/geopandas/__init__.py in <module>
----> 1 from geopandas._config import options # noqa
2
3 from geopandas.geoseries import GeoSeries # noqa
4 from geopandas.geodataframe import GeoDataFrame # noqa
5 from geopandas.array import points_from_xy # noqa
~/miniconda3/lib/python3.9/site-packages/geopandas/_config.py in <module>
124 use_pygeos = Option(
125 key="use_pygeos",
--> 126 default_value=_default_use_pygeos(),
127 doc=(
128 "Whether to use PyGEOS to speed up spatial operations. The default is True "
~/miniconda3/lib/python3.9/site-packages/geopandas/_config.py in
_default_use_pygeos()
110
111 def _default_use_pygeos():
--> 112 import geopandas._compat as compat
113
114 return compat.USE_PYGEOS
~/miniconda3/lib/python3.9/site-packages/geopandas/_compat.py in <module>
6
7 import pandas as pd
----> 8 import pyproj
9 import shapely
10 import shapely.geos
~/miniconda3/lib/python3.9/site-packages/pyproj/__init__.py in <module>
78 warnings.warn(str(err))
79
---> 80 pyproj.network.set_ca_bundle_path()
AttributeError: partially initialized module 'pyproj' has no attribute 'network' (most likely due to a circular import)

ImportError: cannot import name 'is_string_like' from 'matplotlib.cbook

<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

Matplotlib on Windows - dependency unresolved

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.

Categories

Resources