Search code examples
pythonmatplotlibpipapple-m1arm64

Used Migration Assistant to migrate from an Intel Mac to a newer M1 Mac. Now some of my Python programs aren't working due to ImportError


I used Migration Assistant to migrate everything from an Intel Mac to an M1 Mac. Now, when I attempt to run the python program Tiling_2023, which uses matplotlib, I get the following error:

> python Tiling_2023.py 
Traceback (most recent call last):
  File "/Users/Ryan/My Corner/Projects/Python/Tiling/Tiling_2023.py", line 5, in <module>
    import numpy as np, itertools as it, bisect as b, copy, math, matplotlib.pyplot as plt, matplotlib.ticker as mticker, functools, os
  File "/Users/Ryan/.pyenv/versions/3.10.0/lib/python3.10/site-packages/matplotlib/__init__.py", line 131, in <module>
    from . import _api, _version, cbook, _docstring, rcsetup
  File "/Users/Ryan/.pyenv/versions/3.10.0/lib/python3.10/site-packages/matplotlib/rcsetup.py", line 27, in <module>
    from matplotlib.colors import Colormap, is_color_like
  File "/Users/Ryan/.pyenv/versions/3.10.0/lib/python3.10/site-packages/matplotlib/colors.py", line 51, in <module>
    from PIL import Image
  File "/Users/Ryan/.local/lib/python3.10/site-packages/PIL/Image.py", line 103, in <module>
    from . import _imaging as core
ImportError: dlopen(/Users/Ryan/.local/lib/python3.10/site-packages/PIL/_imaging.cpython-310-darwin.so, 0x0002): tried: '/Users/Ryan/.local/lib/python3.10/site-packages/PIL/_imaging.cpython-310-darwin.so' (mach-o file, but is an incompatible architecture (have (x86_64), need (arm64e)))

How do I fix this? I tried pip uninstalling matplotlib and installing it again using pip install --no-binary :all: matplotlib as suggested on another question about a potentially similar-sounding issue, but that did not work. I'm using Python version 3.10.0 with pyenv.


Solution

  • pip install --upgrade --force-reinstall matplotlib fixed the issue by forcing pip to reinstall matplotlib and all its dependencies.