Python: Jupyter and Spyder questions on Matplotlib import pyplot as plt error

Here is the code I received. I have already installed matplotlib as conda install matplotlib. Import matplotlib has not issues. Does anyone know what could be the problem?

ImportError                               Traceback (most recent call last)
<ipython-input-2-99ba79ecbbfb> in <module>
----> 1 from matplotlib import pyplot as plt

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in <module>
   2280     dict.__setitem__(rcParams, "backend", rcsetup._auto_backend_sentinel)
   2281 # Set up the backend.
-> 2282 switch_backend(rcParams["backend"])
   2283 
   2284 # Just to be safe.  Interactive mode can be turned on without

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\pyplot.py in switch_backend(newbackend)
    219         else "matplotlib.backends.backend_{}".format(newbackend.lower()))
    220 
--> 221     backend_mod = importlib.import_module(backend_name)
    222     Backend = type(
    223         "Backend", (matplotlib.backends._Backend,), vars(backend_mod))

C:\ProgramData\Anaconda3\lib\importlib\__init__.py in import_module(name, package)
    125                 break
    126             level += 1
--> 127     return _bootstrap._gcd_import(name[level:], package, level)
    128 
    129 

C:\ProgramData\Anaconda3\lib\site-packages\ipykernel\pylab\backend_inline.py in <module>
      7 
      8 import matplotlib
----> 9 from matplotlib.backends.backend_agg import (
     10     new_figure_manager,
     11     FigureCanvasAgg,

C:\ProgramData\Anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py in <module>
     48 
     49 if _has_pil:
---> 50     from PIL import Image
     51 
     52 backend_version = 'v2.2'

~\AppData\Roaming\Python\Python38\site-packages\PIL\Image.py in <module>
     92     # Also note that Image.core is not a publicly documented interface,
     93     # and should be considered private and subject to change.
---> 94     from . import _imaging as core
     95 
     96     if __version__ != getattr(core, "PILLOW_VERSION", None):

ImportError: cannot import name '_imaging' from 'PIL' (C:\Users\lmdom\AppData\Roaming\Python\Python38\site-packages\PIL\__init__.py)

from matplotlib import pyplot as plt

You have crossed libraries (~\AppData\Roaming\Python\Python38\site-packages\PIL vs C:\ProgramData\Anaconda3\lib\site-packages\) I’m not sure what your solution is, but I’d re-install pillow using conda.

1 Like

Yes it worked thank you so much! you are great! Looking forward to connecting with you.