[Python] Importing matplotlib with conda

Discussão em 'Python' iniciado por Stack, Maio 8, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to import matplotlib. I have installed matplotlib through:

    conda install matplotlib


    When attempting to import matplotlib as follows:

    import matplotlib


    I get the following error:

    import matplotlib
    ---------------------------------------------------------------------------
    ImportError Traceback (most recent call last)
    Cell In[2], line 1
    ----> 1 import matplotlib

    File ~\AppData\Local\spyder-6\envs\spyder-runtime\Lib\site-packages\matplotlib\__init__.py:161
    157 from packaging.version import parse as parse_version
    159 # cbook must import matplotlib only within function
    160 # definitions, so it is safe to import from it here.
    --> 161 from . import _api, _version, cbook, _docstring, rcsetup
    162 from matplotlib._api import MatplotlibDeprecationWarning
    163 from matplotlib.rcsetup import cycler # noqa: F401

    File ~\AppData\Local\spyder-6\envs\spyder-runtime\Lib\site-packages\matplotlib\rcsetup.py:28
    26 from matplotlib.backends import BackendFilter, backend_registry
    27 from matplotlib.cbook import ls_mapper
    ---> 28 from matplotlib.colors import Colormap, is_color_like
    29 from matplotlib._fontconfig_pattern import parse_fontconfig_pattern
    30 from matplotlib._enums import JoinStyle, CapStyle

    File ~\AppData\Local\spyder-6\envs\spyder-runtime\Lib\site-packages\matplotlib\colors.py:52
    49 from numbers import Real
    50 import re
    ---> 52 from PIL import Image
    53 from PIL.PngImagePlugin import PngInfo
    55 import matplotlib as mpl

    File ~\AppData\Local\spyder-6\envs\spyder-runtime\Lib\site-packages\PIL\Image.py:90
    81 MAX_IMAGE_PIXELS: int | None = int(1024 * 1024 * 1024 // 4 // 3)
    84 try:
    85 # If the _imaging C module is not present, Pillow will not load.
    86 # Note that other modules should not refer to _imaging directly;
    87 # import Image and use the Image.core variable instead.
    88 # Also note that Image.core is not a publicly documented interface,
    89 # and should be considered private and subject to change.
    ---> 90 from . import _imaging as core
    92 if __version__ != getattr(core, "PILLOW_VERSION", None):
    93 msg = (
    94 "The _imaging extension was built for another version of Pillow or PIL:\n"
    95 f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
    96 f"Pillow version: {__version__}"
    97 )

    ImportError: DLL load failed while importing _imaging: The specified module could not be found.


    Can you help me fix this, I am new to python

    I tried installing and uninstalling the pillow and matplotlib packages through:

    conda uninstall pillow
    conda install pillow
    conda uninstall matplotlib
    conda install matplotlib

    Continue reading...

Compartilhe esta Página