I apologize if this is a noob question, but: Starting this week, I have been unable to import matplotlib through Spyder. I have not had this issue before.
I am using a MacBook running MacOS 15.3.1 and an ARM M2 chip. This error was on Python 3.11
Updating matplotlib, Spyder, and python did not help.
The code I ran was literally just: import matplotlib.pyplot as plt
Here is the error I received. I have replaced all instances of my username with "[NAME]".
Note that /Users/[NAME]/anaconda3/lib/python3.11/site-packages/PIL/_imaging.cpython-311-darwin.so exists.
What is causing this error and how do I fix it?
%runfile /Users/[NAME]/anaconda3/lib/python3.11/http/untitled2.py --wdir
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
File ~/anaconda3/lib/python3.11/site-packages/spyder_kernels/customize/utils.py:209, in exec_encapsulate_locals(code_ast, globals, locals, exec_fun, filename)
207 if filename is None:
208 filename = "<stdin>"
--> 209 exec_fun(compile(code_ast, filename, "exec"), globals, None)
210 finally:
211 if use_locals_hack:
212 # Cleanup code
File ~/anaconda3/lib/python3.11/http/untitled2.py:9
1 #!/usr/bin/env python3
2 # -*- coding: utf-8 -*-
3 """
4 Created on Sat Mar 15 15:12:11 2025
5
6 @author: [NAME]
7 """
----> 9 import matplotlib.pyplot as plt
File ~/anaconda3/lib/python3.11/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 ~/anaconda3/lib/python3.11/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 ~/anaconda3/lib/python3.11/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 ~/anaconda3/lib/python3.11/site-packages/PIL/Image.py:84
75 MAX_IMAGE_PIXELS = int(1024 * 1024 * 1024 // 4 // 3)
78 try:
79 # If the _imaging C module is not present, Pillow will not load.
80 # Note that other modules should not refer to _imaging directly;
81 # import Image and use the Image.core variable instead.
82 # Also note that Image.core is not a publicly documented interface,
83 # and should be considered private and subject to change.
---> 84 from . import _imaging as core
86 if __version__ != getattr(core, "PILLOW_VERSION", None):
87 msg = (
88 "The _imaging extension was built for another version of Pillow or PIL:\n"
89 f"Core version: {getattr(core, 'PILLOW_VERSION', None)}\n"
90 f"Pillow version: {__version__}"
91 )
ImportError: dlopen(/Users/[NAME]/anaconda3/lib/python3.11/site-packages/PIL/_imaging.cpython-311-darwin.so, 0x0002): Library not loaded: @rpath/libtiff.5.dylib
Referenced from: <B3C0C665-A4DE-3282-A587-6B0B5F8FD71C> /Users/[NAME]/anaconda3/lib/python3.11/site-packages/PIL/_imaging.cpython-311-darwin.so
Reason: tried: '/Users/[NAME]/anaconda3/lib/python3.11/site-packages/PIL/../../../libtiff.5.dylib' (no such file), '/Users/[NAME]/anaconda3/lib/python3.11/site-packages/PIL/../../../libtiff.5.dylib' (no such file), '/Users/[NAME]/anaconda3/bin/../lib/libtiff.5.dylib' (no such file), '/Users/[NAME]/anaconda3/bin/../lib/libtiff.5.dylib' (no such file), '/usr/local/lib/libtiff.5.dylib' (no such file), '/usr/lib/libtiff.5.dylib' (no such file, not in dyld cache)```